# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1037114 | 1L1YA | Power Plant (JOI20_power) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//1L1YA
#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3,unrool-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define Pb push_back
#define F first
#define S second
#define endl '\n'
#define sep ' '
#define all(x) x.begin(),x.end()
#define al(x,n) x+1,x+n+1
#define SZ(x) ((int)x.size())
#define lc (id<<1)
#define rc (lc|1)
#define mid (l+r>>1)
#define dokme(x) cout << x << endl, exit(0)
#define sik(x) cout << x << endl;continue;
#define FastIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define FileIO freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll oo=1e18;
const int mod=1e9+7;
const int inf=1e9+111;
const int N=2e5+11;
const int lg=23;
int n,ans,a[N],dp[N];
vector<int> adj[N];
void dfs(int v,int p=0){
int mx=0;
for(int u: adj[v])
if(u!=p){
dfs(u,v);
dp[v]+=dp[u];
mx=max(mx,dp[u]);
}
dp[v]-=a[v];
ans=max(ans,mx+a[v]);
dp[v]=max(dp[v],a[]);
ans=max(ans,dp[v]);
}
int main(){
FastIO
cin >> n;
for(int i=1;i<n;i++){
int u,v;
cin >> u >> v;
adj[u].Pb(v);
adj[v].Pb(u);
}
for(int i=1;i<=n;i++){
char c;cin >> c;
a[i]=c-'0';
}
dfs(1);
cout << ans << endl;
return 0;
}