fork download
  1. import java.util.*;
  2. public class Main{
  3. public static void main(String[] args){
  4. Scanner sc = new Scanner(System.in);
  5. int n =sc.nextInt();
  6. int m = sc.nextInt();
  7. int [][]b = new int[n+1][n+1];
  8.  
  9.  
  10. for(int i = 1;i<=m;i++){
  11. int x = sc.nextInt();
  12. int y = sc.nextInt();
  13. b[x][y]=1;
  14. b[y][x]=1;
  15.  
  16.  
  17. }
  18. for(int i=1;i<=n;i++){
  19. int count =0;
  20. for(int j=1;j<=n;j++){
  21.  
  22.  
  23. if(b[i][j]==1){
  24. count++;
  25. }
  26.  
  27.  
  28. }
  29. System.out.println(i +" " + count);
  30.  
  31. }
  32. }
  33. }
  34.  
Success #stdin #stdout 0.15s 60916KB
stdin
5 4 
0 1 
1 2 
2 3 
4 2
stdout
1 1
2 3
3 1
4 1
5 0