fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5.  
  6. int main()
  7. {
  8. int Node,Edge,node1,node2,cost;
  9. vector<int>nodes[100],costs[100];
  10. //vector<int>::iterator it;
  11. cout<<"Enter numbers of nodes: "<<endl;
  12. cin>>Node;
  13. cout<<"Enter numbers of edges: "<<endl;
  14. cin>>Edge;
  15. for(int i=0;i<Edge;i++){
  16. cout<<i+1<<"th edge's Node1: ";
  17. cin>>node1;
  18. cout<<i+1<<"th edge's Node2: ";
  19. cin>>node2;
  20. cout<<"Cost from "<<node1<<" to"<<node2<<": ";
  21. cin>>cost;
  22. cout<<endl;
  23. nodes[node1].push_back(node2);
  24. costs[node1].push_back(cost);
  25. }
  26. for(auto& n : nodes) {
  27. for(int i=0;i<n.size();i++){
  28. cout<<n[i]<<" ";
  29. }
  30. cout <<endl;
  31. }
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0s 3420KB
stdin
5 4 
0 2 300
0 3 250
2 3 150
4 1 75
stdout
Enter numbers of nodes: 
Enter numbers of edges: 
1th edge's Node1: 1th edge's Node2: Cost from 0 to2: 
2th edge's Node1: 2th edge's Node2: Cost from 0 to3: 
3th edge's Node1: 3th edge's Node2: Cost from 2 to3: 
4th edge's Node1: 4th edge's Node2: Cost from 4 to1: 
2 3 

3 

1