이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
string s;
vector<int> graph[200001];
int dp[200001], ans = 1;
void dfs(int node = 1, int parent = 0) {
int mx = 0;
for (int i : graph[node]) if (i != parent) {
dfs(i, node);
dp[node] += dp[i];
mx = max(mx, dp[i]);
}
dp[node] = max(s[node - 1] - '0', dp[node] - s[node - 1] + '0');
ans = max(ans, max(mx + s[node - 1] - '0', dp[node]));
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int n;
cin >> n;
for (int i = 1; i < n; i++) {
int a, b;
cin >> a >> b;
graph[a].push_back(b);
graph[b].push_back(a);
}
cin >> s;
dfs();
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |