Guest User

গ্রাফ থিওরি

a guest
Dec 30th, 2012
633
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<vector>
  4. #include<algorithm>
  5. #define MAX 100000
  6. using namespace std;
  7.  
  8. //vector<int>v[100000];
  9. vector<int>node[MAX];
  10. int in[MAX];
  11. int out[MAX];
  12. int main()
  13. {
  14.     //string str;
  15.     int i,j,item,n,edge,pre,post;
  16.     cin >> n >> edge ;
  17.     for(i=0; i<edge; ++i)
  18.     {
  19.         cin >> pre >> post;
  20.         node[pre].push_back(post);
  21.     }
  22.     //sort(node.begin(),node.end());
  23.     cout << "nodes are joined among:" << endl;
  24.     for(i=0; i<=n; ++i)
  25.     {
  26.         for(j=0; j<node[i].size(); ++j)
  27.         {
  28.             ++out[i];
  29.             ++in[node[i][j]];
  30.             if(!j)
  31.             {
  32.                 cout << i << " >> ";
  33.             }
  34.             if(j)cout<<",";cout << node[i][j];
  35.         }
  36.         cout << endl;
  37.     }
  38.     cout << "indegree & outdegree" << endl;
  39.     for(i=0; i<=n; ++i)
  40.     {
  41.         if(i)
  42.         cout << i << " " << "in:" << in[i] << ", " << "out: " << out[i] <<endl;
  43.     }
  44.  
  45.     //node.clear();
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment