This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define ll long long
#define int long long
const int nmax = 2e5 + 5, N = 1e5;
const ll oo = 1e18;
const int lg = 19, M = 2, mod = 1e6;
#define pii pair<ll, ll>
#define fi first
#define se second
#define debug(a, n) for(int i = 1; i <= n; ++i) cout << a[i] << ' '; cout << "\n";
#define endl "\n"
#define task "code"
using namespace std;
int n;
vector<int> adj[nmax];
int f[nmax], c[nmax];
void dfs(int u, int p){
bool ok = 1;
for(auto v : adj[u]){
if(v == p) continue;
dfs(v, u);
f[u] += f[v];
}
if(!f[u]) f[u] += c[u];
}
//void dfs_2(int u, int p){
// for(int i = 1; i <= m; ++i){
// int v = adj[u][i];
// pre[]
// if(v == p) continue;
// }
//}
main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// freopen(task".inp", "r", stdin);
// freopen(task".out", "w", stdout);
cin >> n;
for(int i = 1; i < n; ++i){
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i =1 ; i <= n; ++i){
char x;
cin >> x;
c[i] = (x == '1');
}
dfs(1, -1);
int ans =0;
for(int i = 1; i <= n; ++i) ans = max(ans, f[i] +c[i] - (f[i] == 1));
cout << ans;
}
/*
2 3
0 0 1
0 0 0
3
2 2
2 1
1 2
sort theo x + y
*/
Compilation message (stderr)
power.cpp: In function 'void dfs(long long int, long long int)':
power.cpp:24:10: warning: unused variable 'ok' [-Wunused-variable]
24 | bool ok = 1;
| ^~
power.cpp: At global scope:
power.cpp:40:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
40 | main(){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |