From 170dd6a1e6af89bc1d3fe8ddcd84640c5b9ce20d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=EC=9C=A0=ED=99=98?= Date: Mon, 29 Sep 2025 10:49:05 +0900 Subject: [PATCH] =?UTF-8?q?25515=EB=B2=88=20=ED=92=80=EC=9D=B4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Appendix E/solutions/25515.cpp | 35 ++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/Appendix E/solutions/25515.cpp b/Appendix E/solutions/25515.cpp index 6c991660..9fb37616 100644 --- a/Appendix E/solutions/25515.cpp +++ b/Appendix E/solutions/25515.cpp @@ -1,11 +1,38 @@ -// Authored by : BaaaaaaaaaaarkingDog +// Authored by : uhwan0723 // Co-authored by : - -// http://boj.kr/**************** +// http://boj.kr/190a0fda546b4e47971e626d4a329620 #include using namespace std; +const int mn = 1e5 + 5; +int n, val[mn]; +vector adj[mn]; + +/* +dfs(cur) = 정점 cur을 방문할 때 정수 합의 최댓값 + = cur의 모든 자식 ch에 대해 max(0, dfs(cur, ch)) 값들의 합 + 정점 cur에 적힌 정수 +*/ +long long dfs(int par, int cur){ + long long res = val[cur]; + for(int nxt : adj[cur]){ + if(nxt == par) continue; + res += max(1LL*0, dfs(cur, nxt)); + } + return res; +} + int main(void){ ios::sync_with_stdio(0); cin.tie(0); - -} \ No newline at end of file + cin >> n; + for(int i = 0; i < n-1; ++i){ + int u, v; + cin >> u >> v; + adj[u].push_back(v); + adj[v].push_back(u); + } + for(int i = 0; i < n; ++i) + cin >> val[i]; + + cout << dfs(-1, 0); +}