-
Notifications
You must be signed in to change notification settings - Fork 0
/
B.cpp
59 lines (45 loc) · 1.03 KB
/
B.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
vector<ll> v[105];
ll vis[105];
int main(){
fast;
ll n,m,x,y;
cin>>n>>m;
for(ll i=0;i<m;i++){
cin>>x>>y;
v[x].push_back(y);
v[y].push_back(x);
}
memset(vis, 0 , sizeof(vis));
queue<pair<ll,ll>> q;
q.push({1,1});
vis[1] = 1;
ll cycle=0;
while(!q.empty()){
auto val = q.front();
q.pop();
ll f = val.first, s = val.second;
for(ll u: v[f]){
if(!vis[u]){
q.push({u,f});
vis[u] = 1;
} else if(u!=s){
cycle++;
}
}
}
cycle/=2;
ll allvisited=1;
for(ll i=1;i<=n;i++)
if(!vis[i])
allvisited=0;
if(allvisited && cycle==1)
cout<<"FHTAGN!"<<endl;
else
cout<<"NO"<<endl;
return 0;
}