A8221 | Cthulhu
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super weapon. Due to high seismic activity and poor weather conditions the satellites haven't yet been able to make clear shots of the monster. The analysis of the first shot resulted in an undirected graph with $n$ vertices and $m$ edges. Now the world's best minds are about to determine whether this graph can be regarded as Cthulhu or not.
To add simplicity, let's suppose that Cthulhu looks from the space like some spherical body with tentacles attached to it. Formally, we shall regard as Cthulhu such an undirected graph that can be represented as a set of three or more rooted trees, whose roots are connected by a simple cycle.
It is guaranteed that the graph contains no multiple edges and self-loops.

Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super weapon. Due to high seismic activity and poor weather conditions the satellites haven't yet been able to make clear shots of the monster. The analysis of the first shot resulted in an undirected graph with $n$ vertices and $m$ edges. Now the world's best minds are about to determine whether this graph can be regarded as Cthulhu or not.
To add simplicity, let's suppose that Cthulhu looks from the space like some spherical body with tentacles attached to it. Formally, we shall regard as Cthulhu such an undirected graph that can be represented as a set of three or more rooted trees, whose roots are connected by a simple cycle.
It is guaranteed that the graph contains no multiple edges and self-loops.

输入格式
The first line contains two integers — the number of vertices $n$ and the number of edges $m$ of the graph ($1 \le n \le 100$, $0 \le m \le \frac{n(n-1)}{2}$).
Each of the following $m$ lines contains a pair of integers $x$ and $y$, that show that an edge exists between vertices $x$ and $y$ ($1 \le x, y \le n, x \ne y$). For each pair of vertices there will be at most one edge between them, no edge connects a vertex to itself.
Each of the following $m$ lines contains a pair of integers $x$ and $y$, that show that an edge exists between vertices $x$ and $y$ ($1 \le x, y \le n, x \ne y$). For each pair of vertices there will be at most one edge between them, no edge connects a vertex to itself.
输出格式
Print "NO", if the graph is not Cthulhu and "FHTAGN!" if it is.
输入输出样例
输入 #1
6 6 6 3 6 4 5 1 2 5 1 4 5 4
输出 #1
FHTAGN!
输入 #2
6 5 5 6 4 6 3 1 5 1 1 2
输出 #2
NO
Let us denote as a simple cycle a set of $v$ vertices that can be numbered so that the edges will only exist between vertices number $1$ and $2$ , $2$ and $3$ , ..., $v-1$ and $v$ , $v$ and $1$ .
A tree is a connected undirected graph consisting of $n$ vertices and $n-1$ edges ( $n>0$ ).
A rooted tree is a tree where one vertex is selected to be the root.
A tree is a connected undirected graph consisting of $n$ vertices and $n-1$ edges ( $n>0$ ).
A rooted tree is a tree where one vertex is selected to be the root.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted