fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int graph[10000][10000];
  5.  
  6. int main() {
  7. int n, m;
  8. cin >> n >> m;
  9.  
  10. for(int i=0; i<m; i++) {
  11. // taking input of undirected graph
  12. int x, y;
  13. cin >> x >> y;
  14.  
  15. graph[x][y] = 1;
  16. graph[y][x] = 1;
  17. }
  18.  
  19. for(int i=0; i<n; i++) {
  20. int c = 0;
  21. for(int j=0; j<n; j++) {
  22. if(graph[i][j] == 1) {
  23. c++;
  24. }
  25. }
  26. cout << i << " " << c << endl;
  27. }
  28. return 0;
  29. }
Success #stdin #stdout 0s 5556KB
stdin
5 4
0 1
1 2
2 3
2 4
stdout
0 1
1 2
2 3
3 1
4 1