#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,e) for (int i = s; i <= e; ++i)
#define pb push_back
typedef vector<int> vi;
const int mx=2e5;
vi adj[mx+1];
int ans = 0;
string s;
int dfs (int u, int p) {
int x = 0;
for (int v : adj[u]) {
if (v==p) continue;
x += dfs (v, u);
}
if (s[u-1]=='1') {
ans = max(ans, x+1);
x = max(x-1, 1);
}
ans = max(ans, x);
return x;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;cin>>n;
rep(i,1,n-1){
int u,v; cin>>u>>v;
adj[u].pb(v);
adj[v].pb(u);
}
cin >> s;
dfs (1,0);
cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |