Advertisement
Neychok

НАЙ-ЗАПАЗЕНА ПЪТНА МРЕЖА

Jan 25th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <queue>
  4. using namespace std;
  5. #define MAXN 1000;
  6. #define MAXM 1500;
  7.  
  8. int main() {
  9.     vector<vector<int>> G;
  10.     int res = 0;
  11.     int gradove;
  12.     int putishta;
  13.     cin >> gradove;
  14.     cin >> putishta;
  15.     while (putishta > 0) {
  16.         vector<int> g;
  17.         int a;
  18.         int b;
  19.         cin >> a;
  20.         cin >> b;
  21.         g.push_back(a);
  22.         g.push_back(b);
  23.         G.push_back(g);
  24.         putishta--;
  25.     }
  26.     for (int i = 0; i < G.size(); i++) {
  27.         if (G[i][0] != 0) {
  28.             int resultCount = 1;
  29.             queue<int> que;
  30.             que.push(G[i][0]);
  31.             G[i][0] = 0;
  32.             que.push(G[i][1]);
  33.             G[i][1] = 0;
  34.             while (que.size() > 0) {
  35.                 for (int j = i + 1; j < G.size(); j++) {
  36.                     if (G[j][0] == que.front()) {
  37.                         resultCount++;
  38.                         que.push(G[j][1]);
  39.                         G[j][0] = 0;
  40.                         G[j][1] = 0;
  41.                     }
  42.                 }
  43.                 for (int j = i + 1; j < G.size(); j++) {
  44.                     if (G[j][1] == que.front()) {
  45.                         resultCount++;
  46.                         que.push(G[j][0]);
  47.                         G[j][0] = 0;
  48.                         G[j][1] = 0;
  49.                     }
  50.                 }
  51.                 que.pop();
  52.             }
  53.             if (res < resultCount) {
  54.                 res = resultCount;
  55.             }
  56.         }
  57.     }
  58.  
  59.     cout << res;
  60.     system("Pause");
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement