| ps | |
|---|---|
| 링크 | acmicpc.net/… |
| 출처 | BOJ |
| 문제 번호 | 19535 |
| 문제명 | ㄷㄷㄷㅈ |
| 레벨 | 골드 3 |
| 분류 |
조합론 |
| 시간복잡도 | O(n) |
| 인풋사이즈 | n<=300,000 |
| 사용한 언어 | Python 3.13 |
| 제출기록 | 87552KB / 400ms |
| 최고기록 | 320ms |
| 해결날짜 | 2025/12/02 |
"""Solution code for "BOJ 19535. ㄷㄷㄷㅈ".
- Problem link: https://www.acmicpc.net/problem/19535
- Solution link: http://www.teferi.net/ps/problems/boj/19535
Tags: [combinatorics]
"""
import sys
import math
def main():
N = int(sys.stdin.readline())
edges = [
[int(x) - 1 for x in sys.stdin.readline().split()] for _ in range(N - 1)
]
degs = [0] * N
for u, v in edges:
degs[u] += 1
degs[v] += 1
d_count = sum((degs[u] - 1) * (degs[v] - 1) for u, v in edges)
g_count = sum(math.comb(deg_u, 3) for deg_u in degs)
if d_count > g_count * 3:
print('D')
elif d_count < g_count * 3:
print('G')
else:
print('DUDUDUNGA')
if __name__ == '__main__':
main()