keymasterviriya1150

Code (Adjacency List)

May 18th, 2016
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. #include<algorithm>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     //Code (Adjacency Mat.)
  10.     int V,E;
  11.     cout << "Vertex :";
  12.     cin >> V  ;
  13.  
  14.     vector<pair<int,int> > edges[V];
  15.     //map<int, int> edges;
  16.  
  17.     for(int v=0;v<V;v++)
  18.     {  
  19.         //cout <<"v :"<< v << endl;
  20.         cout << "E :";
  21.         cin>> E;   
  22.         for(int e=0;e<E;e++)
  23.         {
  24.            
  25.             //cout <<"e :"<< e;
  26.             int k,w;
  27.             cout << "k :";
  28.             cin>> k;
  29.             cout <<"w :";
  30.             cin>> w;
  31.             edges[v].push_back(make_pair(k, w));
  32.             //edges[v][k] = w;
  33.  
  34.            
  35.            
  36.         }
  37.         cout<<endl;
  38.     }
  39.     /*
  40.         vertex:3
  41.        
  42.         E:2
  43.         k:1
  44.         w:2
  45.        
  46.         k:2
  47.         W:3
  48.         E:1
  49.         k:9
  50.         w:3
  51.        
  52.         E:0
  53.        
  54.     */
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment