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;
vector<int> adj[200005];
string s;
int ans = 0;
int dfs(int node, int par) {
int cur = 0;
for (auto a : adj[node]) {
if (a == par) continue;
int t = dfs(a, node);
if (s[node-1] == '1') ans = max(ans, t + 1);
cur += t;
}
if (s[node-1] == '1') cur = max(cur-1, 1);
ans = max(ans, cur);
return cur;
}
int main() {
int n; cin >> n;
for (int i = 0; i < n-1; i++) {
int a, b; cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
cin >> s;
dfs(1, 1);
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... |