#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define all(x) x.begin(), x.end()
const int N = 200000;
vector <int> adj[N];
int sz[N];
string s;
int par[N];
void dfs(int v, int pa) {
sz[v] = s[v] == '1';
par[v] = pa;
for (int u : adj[v]) if (u != pa) {
dfs(u, v);
sz[v] += sz[u];
}
}
int main() {
ios::sync_with_stdio(false), cin.tie(0);
int n;
cin >> n;
for (int i = 0, u, v; i < n - 1; ++i) {
cin >> u >> v, --u, --v;
adj[u].pb(v), adj[v].pb(u);
}
cin >> s;
dfs(0, -1);
int tot = sz[0];
int ans = 0;
for (int i = 0; i < n; ++i) {
int cnt = 0;
for (int j : adj[i]) if (j != par[i]) {
cnt += sz[j] > 0;
}
cnt += tot - sz[i] > 0;
if (cnt >= 2 && s[i] == '1') {
cnt--;
}
ans = max(ans, cnt);
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
5032 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
5032 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
5032 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |