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