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