fork download
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. class Main {
  5. public static void main(String[] args) {
  6. Scanner sc = new Scanner(System.in);
  7. int t = sc.nextInt();
  8.  
  9. while (t-- > 0) {
  10. int n = sc.nextInt();
  11. int e = sc.nextInt();
  12.  
  13. int[][] mat = new int[n][n];
  14.  
  15. for (int k = 0; k < e; k++) {
  16. int u = sc.nextInt();
  17. int v = sc.nextInt();
  18. mat[u - 1][v - 1] = 1;
  19. mat[v - 1][u - 1] = 1;
  20. }
  21.  
  22. for (int i = 0; i < n; i++) {
  23. int c=0;
  24. for (int j = 0; j < n; j++) {
  25. // System.out.print(mat[i][j] + " ");
  26. if(mat[i][j]==1)
  27. c++;
  28. }
  29. System.out.println(i+" "+c);
  30. }
  31. }
  32. }
  33. }
Success #stdin #stdout 0.18s 58804KB
stdin
1
4 5
1 2
1 3
2 3
3 4
4 1
stdout
0 3
1 2
2 3
3 2