Advertisement
double_trouble

Beams_of_arcs_list(oriented)

Sep 20th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.97 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2.  
  3. #include <iostream>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. class Graph
  9. {
  10. public:
  11.     const int block = -1;
  12.     int vcount, acount;
  13.     vector<int> I, J, C, H, L;
  14.  
  15.     Graph(int _vcount, vector<int>& _i, vector<int>& _j) :vcount(_vcount), I(_i), J(_j), acount(_i.size()) {
  16.         C.assign(acount, 0);
  17.         H.assign(vcount, block);
  18.         L.resize(acount);
  19.         MakeList();
  20.     }
  21.  
  22.     Graph(int _vcount, vector<int>& _i, vector<int>& _j, vector<int>& _c) :vcount(_vcount), I(_i), J(_j), C(_c), acount(_i.size()) {
  23.         H.assign(vcount, block);
  24.         L.resize(acount);
  25.         MakeList();
  26.     }
  27.  
  28.     void makeList() {
  29.         for (int i(0); i < acount; ++i) {
  30.             int _i(I[i]);
  31.             L[i] = H[_i];
  32.             H[_i] = i;
  33.         }
  34.     }
  35.  
  36.     void addArc(int i, int j) {
  37.         L[acount] = H[i];
  38.         H[i] = acount;
  39.         acount++;
  40.     }
  41.  
  42.     void showArcs() {
  43.         cout << "Arcs:" << endl;
  44.         for (int i(0); i < acount; ++i) {
  45.             cout << i + 1 << ": from " << I[i] + 1 << " to " << J[i] + 1 << ", value = " << C[i] << endl;
  46.         }
  47.     }
  48.  
  49.     void showBeamsOfArcs() {
  50.         cout << "Beams of arcs: " << endl;
  51.         vector <int> ArcsList;
  52.         for (int i(0); i < vcount; ++i) {
  53.             ArcsList.clear();
  54.             for (int k(H[i]); k != -1; ) {
  55.                 ArcsList.push_back(k);
  56.                 k = L[k];
  57.             }
  58.  
  59.             int count(ArcsList.size());
  60.  
  61.             switch (count)
  62.             {
  63.             case 0:
  64.                 cout << "From vertex " << i + 1 << " come no arcs";
  65.                 break;
  66.             case 1:
  67.                 cout << "From vertex " << i + 1 << " comes 1 arc: ";
  68.                 break;
  69.             default:
  70.                 cout << "From vertex " << i + 1 << " come " << count << " arcs: ";
  71.             }
  72.            
  73.             if (count > 0) {
  74.                 for (int k(0); k < count - 1; ++k) {
  75.                     cout << ArcsList[k] + 1 << ", ";
  76.                 }
  77.                 cout << ArcsList[count - 1] + 1;
  78.             }
  79.  
  80.             cout << endl;
  81.         }
  82.     }
  83. };
  84.  
  85. int main()
  86. {
  87.     freopen("test.txt", "r", stdin);
  88.  
  89.     int n, m;
  90.     cin >> n >> m;
  91.  
  92.     vector<int> _i, _j;
  93.     int ii, jj;
  94.     for (int i(0); i < m; ++i) {
  95.         cin >> ii >> jj;
  96.         _i.push_back(ii - 1);
  97.         _j.push_back(jj - 1);
  98.     }
  99.  
  100.     Graph G(n, _i, _j);
  101.  
  102.  
  103.     return 0;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement