This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int n, x, y, ans = 0, dp[200001];
vector<int> vec[200001];
string s;
bool visited[200001];
void dfs(int x) {
int maxi = 0;
visited[x] = true;
for(int c : vec[x]) {
if(!visited[c]) {
dfs(c);
dp[x] += dp[c];
maxi = max(dp[c], maxi);
}
}
dp[x] = max(s[x - 1] - '0', dp[x] - s[x - 1] + '0');
ans = max(ans, max(maxi + s[x - 1] - '0', dp[x]));
}
int main() {
cin >> n;
for(int i = 1; i < n; i++) {
cin >> x >> y;
vec[x].push_back(y);
vec[y].push_back(x);
}
cin >> s;
dfs(n);
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |