#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
string s = "0";
int res;
int dp[200005];
vector <int> graf[200005];
void dfs(int v, int par){
for(auto c : graf[v]){
if(c == par) continue;
dfs(c, v);
dp[v] += dp[c];
}
dp[v] += (s[v]-'0');
res = max(res, dp[v]);
dp[v] -= 2*(s[v]-'0');
if(dp[v] < 0) dp[v] += 2*(s[v]-'0');
if(dp[v] == 0 && s[v] == '1') dp[v] = 1;
//cout << v << " " << dp[v] << endl;
}
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
int n;
cin >> n;
for(int i=1; i<n; i++){
int a, b;
cin >> a >> b;
graf[a].push_back(b);
graf[b].push_back(a);
}
string g;
cin >> g;
s += g;
dfs(1, 0);
cout << res;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
4992 KB |
Output is correct |
5 |
Correct |
4 ms |
4992 KB |
Output is correct |
6 |
Correct |
4 ms |
4992 KB |
Output is correct |
7 |
Incorrect |
3 ms |
4992 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
4992 KB |
Output is correct |
5 |
Correct |
4 ms |
4992 KB |
Output is correct |
6 |
Correct |
4 ms |
4992 KB |
Output is correct |
7 |
Incorrect |
3 ms |
4992 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
4992 KB |
Output is correct |
5 |
Correct |
4 ms |
4992 KB |
Output is correct |
6 |
Correct |
4 ms |
4992 KB |
Output is correct |
7 |
Incorrect |
3 ms |
4992 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |