Advertisement
MrFishPL

Cthulhu

Dec 2nd, 2021
1,258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include "iostream"
  2. #include "vector"
  3. #include "queue"
  4. using namespace std;
  5.  
  6.  
  7. int main() {
  8.   int n, m, a, b, v;
  9.   queue<int> Q;
  10.  
  11.   cin >> n >> m;
  12.  
  13.   vector<vector<int>> graf(n, vector<int>());
  14.   bool visited[n] = {false};
  15.  
  16.   for (int i = 0; i<m; i++) {
  17.     cin >> a >> b;
  18.     graf[a-1].push_back(b-1);
  19.     graf[b-1].push_back(a-1);
  20.   }
  21.  
  22.   if (n != m) {
  23.     cout << "NO\n";
  24.     return 0;
  25.   }
  26.  
  27.   Q.push(0);
  28.   visited[0] = true;
  29.  
  30.   while (!Q.empty()) {
  31.     v = Q.front();
  32.     Q.pop();
  33.  
  34.     for (auto neighbor: graf[v]) {
  35.       if (!visited[neighbor]) {
  36.         visited[neighbor] = true;
  37.         Q.push(neighbor);
  38.       }
  39.     }
  40.   }
  41.  
  42.   for (auto vis: visited) {
  43.     if (!vis) {
  44.       cout << "NO\n";
  45.       return 0;
  46.     }
  47.   }
  48.  
  49.   cout << "FHTAGN!\n";
  50.  
  51.   return 0;
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement