fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int u,w;
  6. cin>>u>>w;
  7. vector<vector<int>>adj(u);
  8.  
  9. for(int i=0;i<w;i++)
  10. {
  11. int p,v;
  12. cin>>p>>v;
  13. adj[p].push_back(v);
  14. adj[v].push_back(p);
  15.  
  16. }
  17. for(int i=0;i<u;i++)
  18. {
  19. cout<<i<<":"<<endl;
  20. for(auto l:adj[i])
  21. {
  22. cout<<l<<endl;
  23.  
  24. }
  25. }
  26. }
Success #stdin #stdout 0.01s 5320KB
stdin
4 3
0 1
0 2
1 3
stdout
0:
1
2
1:
0
3
2:
0
3:
1