fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. void dodaj(vector<vector<int>>& adj, int x ,int y){
  7. adj[x].push_back(y);
  8. adj[y].push_back(x);
  9.  
  10. }
  11.  
  12.  
  13. int main() {
  14. int v;
  15. cin>>v;
  16. vector<vector<int>> adj(v);
  17. int k,x,y;
  18. cin>>k;
  19. for(int i=0; i<k; i++){
  20. cin>>x>>y;
  21. dodaj(adj,x,y);
  22. }
  23.  
  24. for(int i=0; i<v; i++){
  25. sort(adj[i].begin(), adj[i].end());
  26. cout<<"sasiedz "<<i<<" to ";
  27. for(int j: adj[i])
  28. cout<<j<<" ";
  29. cout<<endl;
  30.  
  31. }
  32. return 0;
  33. }
Success #stdin #stdout 0.01s 5320KB
stdin
5 7
1 2
3 2
2 4
1 0
0 3
1 4
3 4
stdout
sasiedz 0 to 1 3 
sasiedz 1 to 0 2 4 
sasiedz 2 to 1 3 4 
sasiedz 3 to 0 2 4 
sasiedz 4 to 1 2 3