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. map<int,list<int>>v1;
  9. for(int i=0;i<m;i++){
  10. int u,v;
  11. cin>>u>>v;
  12. v1[u].push_back(v);
  13. v1[v].push_back(u);
  14. }
  15. for(auto i:v1){
  16. cout<<i.first<<"-";
  17. for(auto x:i.second){
  18. cout<<x<<" ";
  19. }
  20. cout<<"\n";
  21. }
  22. return 0;
  23. }
Success #stdin #stdout 0.01s 5456KB
stdin
5 7
0 1
0 4
1 2
1 3
1 4
2 3
3 4
stdout
0-1 4 
1-0 2 3 4 
2-1 3 
3-1 2 4 
4-0 1 3