이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
vector <int> g[N];
int dp[N], n;
char a[N];
int dfs(int nod, int dad)
{
int st = a[nod] - '0', bst_son = 0, bst = 0;
for (auto x : g[nod])
{
if (x == dad)
continue;
bst = max(bst, dfs(x, nod));
dp[nod] += dp[x];
bst_son = max(bst_son, dp[x]);
}
dp[nod] = max(st, dp[nod] - st); ///a or b...
return max(bst, max(dp[nod], bst_son + st));
}
int main()
{
cin >> n;
for (int i = 1; i < n; i++)
{
int a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
cin >> a + 1;
cout << dfs(1, 0);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
power.cpp: In function 'int main()':
power.cpp:32:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
32 | cin >> a + 1;
| ~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |