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.  
  8. public class Main
  9. {
  10. public static void main (String[] args)
  11. {
  12. Scanner scanner = new Scanner (System.in);
  13.  
  14. int n = scanner.nextInt();
  15. int m = scanner.nextInt();
  16.  
  17. int [][] A = new int [1000] [1000];
  18.  
  19. for (int i = 1; i <= m; i++) {
  20.  
  21. int x, y;
  22. x = scanner.nextInt();
  23. y = scanner.nextInt();
  24. A[x][y] = 1;
  25. A[y][x] = 1;
  26. }
  27.  
  28. for (int i = 0; i < n; i++) {
  29. int c = 0;
  30. for (int j = 0; j < n; j++) {
  31. if (A[i][j] == 1) {
  32. c++;
  33. }
  34. }
  35. System.out.println(i + " " + c);
  36. }
  37. }
  38. }
Success #stdin #stdout 0.18s 60896KB
stdin
5 4 
0 1 
1 2 
2 3 
4 2 
stdout
0 1
1 2
2 3
3 1
4 1