Skip to content

Commit

Permalink
Merge pull request #214 from AlgoLeadMe/62-tgyuuAn
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyuuAn authored Jul 9, 2024
2 parents 4467fda + 78caf67 commit bafecdf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tgyuuAn/DP/์šฐ์ˆ˜ ๋งˆ์„.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import sys
from collections import defaultdict

sys.setrecursionlimit(10**6)

def input(): return sys.stdin.readline().rstrip()

N = int(input())
town = [0]
town.extend(list(map(int,input().split())))
linked = defaultdict(set)

for _ in range(N-1):
first, second = map(int,input().split())

linked[first].add(second)
linked[second].add(first)

DP = [[0, town[n]] for n in range(N+1)]
visited = set()

def dfs(now):
visited.add(now)

for next in linked[now]:
if next not in visited:
dfs(next)
DP[now][1] += DP[next][0]
DP[now][0] += max(DP[next][0], DP[next][1])

dfs(1)
print(max(DP[1][1], DP[1][0]))
1 change: 1 addition & 0 deletions tgyuuAn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@
| 59์ฐจ์‹œ | 2024.06.03 | ๋‹ค์ต์ŠคํŠธ๋ผ + ์ด๋ถ„ ํƒ์ƒ‰ | <a href="https://www.acmicpc.net/problem/14942">๊ฐœ๋ฏธ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/207
| 60์ฐจ์‹œ | 2024.06.07 | ๊ทธ๋ฆฌ๋”” | <a href="https://www.acmicpc.net/problem/14939">๋ถˆ ๋„๊ธฐ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/209
| 61์ฐจ์‹œ | 2024.06.20 | ํฌ๋ฃจ์Šค์นผ | <a href="https://www.acmicpc.net/problem/1774">์šฐ์ฃผ์‹ ๊ณผ์˜ ๊ต๊ฐ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/212
| 62์ฐจ์‹œ | 2024.07.01 | DP | <a href="https://www.acmicpc.net/problem/1949">์šฐ์ˆ˜ ๋งˆ์„</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/214
---

0 comments on commit bafecdf

Please sign in to comment.