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. Scanner sc = new Scanner(System.in);
  13. int n = sc.nextInt();
  14. int m = sc.nextInt();
  15. int [][]b = new int[10000][10000];
  16. for(int i=0;i<m; i++){
  17. int x=0,y=0;
  18. x=sc.nextInt();
  19. y=sc.nextInt();
  20. b[x][y] = 1;
  21. b[y][x] = 1;
  22. }
  23.  
  24. for (int i = 0; i < n; i++) {
  25. int c = 0;
  26. for (int j = 0; j < n; j++) {
  27. if (b[i][j] == 1) {
  28. c++;
  29. }
  30. }
  31. System.out.println(i + " " + c);
  32. }
  33. }
  34. }
Success #stdin #stdout 0.31s 506744KB
stdin
5 4 
0 1 
1 2 
2 3 
4 2 
stdout
0 1
1 2
2 3
3 1
4 1