Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "iostream"
- #include "vector"
- #include "queue"
- using namespace std;
- int main() {
- int n, m, a, b, v;
- queue<int> Q;
- cin >> n >> m;
- vector<vector<int>> graf(n, vector<int>());
- bool visited[n] = {false};
- for (int i = 0; i<m; i++) {
- cin >> a >> b;
- graf[a-1].push_back(b-1);
- graf[b-1].push_back(a-1);
- }
- if (n != m) {
- cout << "NO\n";
- return 0;
- }
- Q.push(0);
- visited[0] = true;
- while (!Q.empty()) {
- v = Q.front();
- Q.pop();
- for (auto neighbor: graf[v]) {
- if (!visited[neighbor]) {
- visited[neighbor] = true;
- Q.push(neighbor);
- }
- }
- }
- for (auto vis: visited) {
- if (!vis) {
- cout << "NO\n";
- return 0;
- }
- }
- cout << "FHTAGN!\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement