#include <bits/stdc++.h>
using namespace std;
# define int long long
# define fir first
# define sec second
# define pb push_back
const int cnst = 2e5+5;
bool mutipletestcase = 0;
//bool debug = false;
vector<int> vec[cnst];
bool id[cnst];
int par[cnst];
int counts[cnst];
int ans = 0;
void dfs(int x) {
int y = 0;
int fre = 0;
for(auto v: vec[x]) {
if(v == par[x]) continue;
par[v] = x;
dfs(v);
y += counts[v];
if(counts[v]) fre++;
}
if(!id[x]) counts[x] = y;
else counts[x] = max(y-1, 1ll);
if(fre == 1) ans = max(ans, y+id[x]);
else ans = max(ans, y-id[x]);
}
void solve() {
int n; cin >> n;
for(int i = 1; i<n; i++) {
int a, b; cin >> a >> b;
vec[a].pb(b);
vec[b].pb(a);
}
string s; cin >> s;
for(int i = 0; i<n; i++) {
id[i+1] = (s[i] == '1');
}
dfs(1);
cout << ans << endl;
}
signed main() {
ios_base::sync_with_stdio(false);
int t = 1;
if(mutipletestcase) cin >> t;
while(t--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
5024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
5024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
5024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |