| 3724 - Caterpillar North America - East Central - 2006/2007 | |||||
| Submit | Ranking | ||||
An undirected graph is called a caterpillar if it is connected, has no cycles, and there is a path in the graph where every node is either on this path or a neighbor of a node on the path. This path is called the spine of the caterpillar and the spine may not be unique. You are simply going to check graphs to see if they are caterpillars.
For example, the left graph below is not a caterpillar, but the right graph is. One possible spine is shown by dots.
There will be multiple test cases. Each test case starts with a line
containing n
For each test case generate one line of output. This line should
either be
100
300
Output
Graph g
or
Graph g
as appropriate, where g
Sample Input
22
21
1 2 2 3 2 4 2 5 2 6 6 7 6 10 10 8 9 10 10 12 11 12 12 13 12 17
18 17 15 17 15 14 16 15 17 20 20 21 20 22 20 19
16
15
1 2 2 3 5 2 4 2 2 6 6 7 6 8 6 9 9 10 10 12 10 11 10 14 10 13 13 16 13
15
0
Sample Output
Graph 1 is not a caterpillar.
Graph 2 is a caterpillar.
East Central 2006-2007