codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

103B.md (2433B)


      1 Source: https://codeforces.com/problemset/problem/103/B
      2 
      3 B. Cthulhu
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 ...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...
     22 
     23 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.
     24 
     25 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.
     26 
     27 It is guaranteed that the graph contains no multiple edges and self-loops.
     28 
     29  ![](https://espresso.codeforces.com/61f746e2fd33d321a4cc0fdce9a73a82096068e7.png)
     30 
     31 Input
     32 
     33 The first line contains two integers — the number of vertices *n* and the number of edges *m* of the graph (1 ≤ *n* ≤ 100, 0 ≤ *m* ≤ ![](https://espresso.codeforces.com/b6fbba87a6e66854e5728f67cc384b75c4bcf131.png)).
     34 
     35 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 ≤ *x*, *y* ≤ *n*, *x* ≠ *y*). For each pair of vertices there will be at most one edge between them, no edge connects a vertex to itself.
     36 
     37 Output
     38 
     39 Print "NO", if the graph is not Cthulhu and "FHTAGN!" if it is.
     40 
     41 Examples
     42 
     43 Input
     44 
     45 ```
     46 6 6  
     47 6 3  
     48 6 4  
     49 5 1  
     50 2 5  
     51 1 4  
     52 5 4
     53 ```
     54 
     55 Output
     56 
     57 ```
     58 FHTAGN!
     59 ```
     60 
     61 Input
     62 
     63 ```
     64 6 5  
     65 5 6  
     66 4 6  
     67 3 1  
     68 5 1  
     69 1 2
     70 ```
     71 
     72 Output
     73 
     74 ```
     75 NO
     76 ```
     77 
     78 Note
     79 
     80 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.
     81 
     82 A tree is a connected undirected graph consisting of *n* vertices and *n* - 1 edges (*n* > 0).
     83 
     84 A rooted tree is a tree where one vertex is selected to be the root.