fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n, m;
  6. cin>>n>>m;
  7. vector<int> graph[n];
  8. for(int i=0;i<m;i++){
  9. int x,y;
  10. cin>>x>>y;
  11. graph[x].push_back(y);
  12. graph[y].push_back(x);
  13. }
  14. for(int i=0;i<n;i++){
  15. int count=graph[i].size();
  16. cout<<"vertex "<<i<<": "<<count<<"\n";
  17. }
  18. return 0;
  19. }
Success #stdin #stdout 0s 5320KB
stdin
3 2
0 1
1 2
stdout
vertex 0: 1
vertex 1: 2
vertex 2: 1