fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. Scanner sc = new Scanner(System.in);
  14.  
  15. int n = sc.nextInt();
  16. int e = sc.nextInt();
  17.  
  18. int[][] graph = new int[100][100];
  19.  
  20. for (int i = 1; i <= e; i++) {
  21. int u, v;
  22. u = sc.nextInt();
  23. v = sc.nextInt();
  24. graph[u][v] = 1;
  25. graph[v][u] = 1;
  26. }
  27.  
  28. for (int u = 0; u < n; u++) {
  29. int count = 0;
  30. for (int v = 0; v < n; v++) {
  31. if (graph[u][v] == 1) {
  32. count++;
  33. }
  34. }
  35. System.out.println(u + " " + count);
  36. }
  37. sc.close();
  38. }
  39. }
Success #stdin #stdout 0.18s 60968KB
stdin
5 4 
0 1 
1 2 
2 3 
4 2 
stdout
0 1
1 2
2 3
3 1
4 1