keymasterviriya1150

Untitled

Sep 8th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.98 KB | None | 0 0
  1. #include<iostream>
  2. #include <vector>
  3. #include <map>
  4. #include <utility>
  5. using namespace std;
  6. void  AdjacencyMat()
  7. {
  8.     int V;
  9.     cin >>V;
  10.     int weight[V][V];
  11.     for(unsigned int m=0;m<V;m++)
  12.             for(unsigned int k=0;k<V;k++)
  13.             {
  14.                 cout << "m="<<m<<" k="<<k<<" weight=";
  15.                 cin >> weight[m][k];
  16.             }
  17.             /*
  18.             3
  19.             weight[0][0]=10
  20.             weight[0][1]=11
  21.             weight[0][2]=12
  22.            
  23.             weight[i][j]=n i>0,j>0
  24.             */         
  25. }
  26. void  AdjacencyMatV2()
  27. {
  28.     int V, E;
  29.     cin >> V >> E;  // Read a number of vertices and edges
  30.     int weight[V][V];
  31.     for (unsigned int e = 0; e < E; e++)
  32.     {
  33.         int i, k, w;
  34.         cin >> i >> k >> w;
  35.         weight[i][k] = w;
  36.     }
  37.     /*
  38.     2 3
  39.     0 1 2
  40.     0 2 3
  41.     1 2 5
  42.     */
  43.    
  44. }
  45. void AdjacencyList()
  46. {
  47.     int V, E;
  48.     cin >> V;
  49.     vector<pair<int, int> > edges[V];
  50.     for (int v = 0; v < V; v++)
  51.     {
  52.         cin >> E;  
  53.         for (int e = 0; e < E; e++)
  54.         {
  55.             int k, w;
  56.             cin >> k >> w;
  57.             edges[v].push_back(make_pair(k, w));
  58.         }
  59.     }
  60.     /*
  61.     0:(1,10),(2,10)
  62.     1:(0,10).(2,30)
  63.     2:(0,30),(1,20)
  64.    
  65.     vector<pair<int, int> >  can't use so long
  66.     */
  67. }
  68. void AdjacencyListV2()
  69. {
  70.     int V, E;
  71.     cin >> V >> E;
  72.     map<int, int> edges;
  73.      for (int v = 0; v < V; v++)
  74.     {  
  75.         cin >> E;
  76.         for (int e = 0; e < E; e++)
  77.         {
  78.          int k, w;
  79.          cin >> k >> w;
  80.          //edges[v][k] = w;
  81.         }
  82.     }
  83.   /*
  84.       STL Map takes  O( N log N)   faster
  85. */
  86. }
  87. void AdjacencyListV3()
  88. {
  89.     int V, E;
  90.     cin >> V >> E;
  91.     vector<int> edges[V]; // Un-weighted Adjacency List
  92.  
  93.     for (int v = 0; v < V; v++)
  94.     {
  95.         cin >> E;
  96.         for (int e = 0; e < E; e++)
  97.         {
  98.             int k;
  99.             cin >> k;
  100.             edges[v].push_back(k);
  101.         }
  102.     }
  103.     /*
  104.         3 3
  105.         2 1 2
  106.         2 0 2
  107.         2 0 1
  108.     */
  109. }
  110. void EdgeList()
  111. {
  112.     int E;
  113.     cin >>E;
  114.     vector<pair<int,int> > edge;
  115.     for (int e = 0; e < (E*2); e++)
  116.     {
  117.         int a,b;
  118.         cin >>a>>b;
  119.         edge.push_back(make_pair(a,b));
  120.     }
  121.     /*
  122.     3
  123.     0:0 1
  124.     1:0 2
  125.     2:1 0
  126.     3:1 2
  127.     4:2 1
  128.     5:2 0
  129.     */
  130. }
Add Comment
Please, Sign In to add comment