fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int n, m;
  7. cin >> n >> m;
  8. vector<vector<int>> matrix(n+1);
  9.  
  10. for (int i = 1; i <= m; i++){
  11. int a, b;
  12. cin >> a >> b;
  13. matrix[a].push_back(b);
  14. matrix[b].push_back(a);
  15. }
  16.  
  17. for (int i = 0; i < n; i++){
  18.  
  19. cout << "The nodes connected to " << i << " is: " << matrix[i].size() << endl;
  20. }
  21. return 0;
  22. }
Success #stdin #stdout 0s 5320KB
stdin
6 5
0 1
1 5
1 2
2 3
2 4
stdout
The nodes connected to 0 is: 1
The nodes connected to 1 is: 3
The nodes connected to 2 is: 3
The nodes connected to 3 is: 1
The nodes connected to 4 is: 1
The nodes connected to 5 is: 1