406149: GYM102279 G Get Higher and Higher

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

G. Get Higher and Highertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

The rivalry of Lowie and B21 have history. That's how the HNOI Civil War was found.

Both are challenged to a contest called: "Who Can Get His Tree Higher?". As straightforward as it sound: Lowie and B21 bring their own trees and get to pick a node of choice as the root, the one who gets his tree to have the greater height of wins the the contest.

To revise: A tree is a connected bidirectional graph with N vertices and N-1 edges. The height of one tree is the greatest distance from the root to one of its leaves. A distance between two nodes on a tree is the number of nodes that are on the simple path between those two nodes.

B21 is a master of trees. He knows how to make the optimal move to make the height of his tree as great as possible by choosing the best root. Meanwhile, Lowie doesn't know it. Lowie will choose a random node to be the root of his tree.

Nevertheless, B21's tree is still way smaller than Lowie's one, so even with an optimal move, B21 would still cannot win this contest. Your job is to show B21 if he still stand any chance to win this contest. A draw is a draw, which means neither player won, and they will find another contest to compete in.

Input

The first line contains an integer: $$$N$$$ ($$$1 \le N \le 10^5$$$) - number of nodes in B21's tree.

The next $$$N$$$ lines, each contains $$$2$$$ integers: $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le N$$$) - denotes that there is an edge connects node $$$u$$$ and node $$$v$$$ in B21's tree.

The next line contains an integer: $$$M$$$ ($$$N < M \le 2*10^5$$$) - number of nodes in Lowie's tree.

The next $$$M$$$ lines, each contains $$$2$$$ integers: $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le N$$$) - denotes that there is an edge connects node $$$u$$$ and node $$$v$$$ in Lowie's tree.

Output

If B21 stand a chance to win, output "GGEZ". Otherwise, output "FF".

ExamplesInput
5
1 2
1 3
2 4
2 5
7
1 2
2 5
3 6
2 4
1 3
3 7
Output
GGEZ
Input
5
1 2
1 3
2 4
2 5
7
1 2
1 3
3 4
4 5
2 6
6 7
Output
FF
Note

In both sample tests, B21 will obtain the maximum height of his tree if he chooses node $$$4$$$ as the root of his tree:

The height of this tree is now $$$4$$$.

In the first example, B21 will win if Lowie choose node $$$1$$$ as the root:

In the second example, even after Lowie made the worst choice of root, the contest would still be a draw, that means B21 cannot win in any way:

加入题单

算法标签: