QOJ.ac

QOJ

Limite de temps : 3 s Limite de mémoire : 1024 MB Points totaux : 100 Hackable ✓

#18698. DDDZ

Statistiques

One day, while staring blankly at a tree, Dong-hyeon discovered a remarkable fact. It is that there are only two types of trees with four vertices: the 'ㄷ' shape and the 'ㅈ' shape!

For any tree with four or more vertices, let us choose a set of four vertices. If we keep only the edges of the original tree that connect two vertices within this set, and these four vertices form a single connected tree, it will be either a 'ㄷ' shape or a 'ㅈ' shape. Let the number of 'ㄷ' shapes and 'ㅈ' shapes in a tree be the number of such sets of four vertices that form a 'ㄷ' shape and a 'ㅈ' shape, respectively.

Now, Dong-hyeon has classified all trees in the world into the following three types:

  • D-tree: A tree where the number of 'ㄷ' shapes is greater than 3 times the number of 'ㅈ' shapes.
  • G-tree: A tree where the number of 'ㄷ' shapes is less than 3 times the number of 'ㅈ' shapes.
  • DUDUDUNGA-tree: A tree where the number of 'ㄷ' shapes is exactly 3 times the number of 'ㅈ' shapes.

Excited, Dong-hyeon started counting the number of 'ㄷ' and 'ㅈ' shapes in every tree he saw. However, he soon encountered a tree with 300,000 vertices and lost his mind. Let's help Dong-hyeon determine whether a given tree is a D-tree, a G-tree, or a DUDUDUNGA-tree!

Input

The first line contains the number of vertices $N$ in the tree. ($4 \le N \le 300\,000$)

From the second line, $N-1$ lines follow, each containing two vertex numbers $u$ and $v$ connected by an edge. ($1 \le u, v \le N$)

Output

If the given tree is a D-tree, print D; if it is a G-tree, print G; if it is a DUDUDUNGA-tree, print DUDUDUNGA.

Examples

Input 1

4
1 2
2 3
3 4

Output 1

D

Input 2

4
1 2
1 3
1 4

Output 2

G

Input 3

6
1 2
2 3
3 4
4 5
4 6

Output 3

DUDUDUNGA

Figure 1. The two types of trees with four vertices: the 'ㄷ' shape (left) and the 'ㅈ' shape (right).

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.