fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int node, edge;
  7. cin>>node>>edge;
  8. vector<pair<int, int> >graph[node+1];
  9.  
  10. int u, v, w;
  11. for(int i = 1; i <= edge; i++)
  12. {
  13. cin>>u>>v>>w;
  14. graph[u].push_back(make_pair(v, w));
  15. graph[v].push_back(make_pair(u, w));
  16. }
  17.  
  18. for(int i = 1; i <= node; i++)
  19. {
  20. cout<<i<<" -> ";
  21. for(int j = 0; j < graph[i].size(); j++)
  22. {
  23. cout<<"("<<graph[i][j].first<<", "<<graph[i][j].second<<") ";
  24. }
  25. cout<<endl;
  26. }
  27.  
  28. }
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
Success #stdin #stdout 0.01s 5316KB
stdin
4 5
1 2 3
2 3 5
3 4 5
4 1 6
2 4 1
stdout
1 -> (2, 3) (4, 6) 
2 -> (1, 3) (3, 5) (4, 1) 
3 -> (2, 5) (4, 5) 
4 -> (3, 5) (1, 6) (2, 1)