From 3b38de5336adfd460cd06bf8a71109de6df27322 Mon Sep 17 00:00:00 2001 From: pu2rile <3o920@naver.com> Date: Thu, 15 Aug 2024 17:15:38 +0900 Subject: [PATCH] 24-08-15 --- pu2rile/README.md | 4 +++ ...0\353\254\264 \355\203\210\354\266\234.py" | 30 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 "pu2rile/\355\212\270\353\246\254/\353\202\230\353\254\264 \355\203\210\354\266\234.py" diff --git a/pu2rile/README.md b/pu2rile/README.md index fec575c..8d285f8 100644 --- a/pu2rile/README.md +++ b/pu2rile/README.md @@ -13,3 +13,7 @@ | 9차시 | 2024.05.27 | 구현 | [오늘도 졌다](https://www.acmicpc.net/problem/14582) | [#29](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/29#issue-2320060288) | 10차시 | 2024.07.11 | 스택 | [화학식량](https://www.acmicpc.net/problem/2257) | [#35](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/35#issue-2403173169) | 11차시 | 2024.07.13 | 우선순위 큐 | [강의실](https://www.acmicpc.net/problem/1374) | [#37](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/37#issue-2406937336) +| 12차시 | 2024.07.23 | 동적 프로그래밍 | [1학년](https://www.acmicpc.net/problem/5557) | [#40](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/40) +| 13차시 | 2024.07.26 | 스택 | [후위 표기식](https://www.acmicpc.net/problem/1918) | [#43](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/43) +| 14차시 | 2024.08.05 | 트리 | [이진 탐색 트리](https://www.acmicpc.net/problem/5639) | [#45](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/45) +| 15차시 | 2024.08.15 | 트리 | [나무 탈출](https://www.acmicpc.net/problem/15900) | [#48](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/48) diff --git "a/pu2rile/\355\212\270\353\246\254/\353\202\230\353\254\264 \355\203\210\354\266\234.py" "b/pu2rile/\355\212\270\353\246\254/\353\202\230\353\254\264 \355\203\210\354\266\234.py" new file mode 100644 index 0000000..5bae824 --- /dev/null +++ "b/pu2rile/\355\212\270\353\246\254/\353\202\230\353\254\264 \355\203\210\354\266\234.py" @@ -0,0 +1,30 @@ +import sys +sys.setrecursionlimit(10 ** 6) + +n = int(sys.stdin.readline().strip()) +# 트리에 저장 +tree = [[] for _ in range (n+1)] +for _ in range(n-1): + a,b = map(int, sys.stdin.readline().strip().split()) + tree[a].append(b) + tree[b].append(a) + +arr = [0] * (n + 1) +def dfs(cur, prv, dep): + arr[cur] = dep # cnt는 현재 노드(cur)까지의 거리를 arr 리스트의 cur 인덱스에 저장 + for next in tree[cur]: # 현재 노드(cur)에 연결된 모든 자식 노드를 순회 + if next == prv: # 다음 노드(next)가 이전에 방문한 부모 노드(prv)라면 + continue # 건너뛰기 + dfs(next,cur,dep+1) # 재귀적으로 dfs 수행, cur이 next 노드의 부모가 되고, cnt + 1을 통해 현재 깊이를 1 증가 + +dfs(1, 0, 0) # 트리 탐색 시작 +cnt = 0 +for i in range(2, n+1): + # 리프 노드의 깊이 더하기 + if len(tree[i]) == 1: + cnt += arr[i] + +if cnt % 2 == 1: + print("Yes") +else: + print("No") \ No newline at end of file