#include <bits/stdc++.h>
using namespace std;
const int N = 3e5;
vector<int>graph[N];
int dp[N];
string s = ":";
int res = 0;
void dfs(int v, int par){
int mx = 0;
for(auto c : graph[v]){
if(c == par) continue;
dfs(c, v);
dp[v] += dp[c];
mx = max(mx, dp[c]);
}
if(s[v] == '1') res = max(res, 1+mx);
else res = max(res, dp[v]);
dp[v] -= s[v]-'0';
if(dp[v] <= 0 && s[v] == '1') dp[v] = 1;
res = max(res, dp[v]);
}
int main(){
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);
}
string t;
cin >> t;
dfs(1, 0);
cout << res << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
7424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
7424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
7424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |