# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
301024 | milisav | Power Plant (JOI20_power) | C++14 | 249 ms | 68344 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.
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#define maxn 2000000
using namespace std;
int n;
vector<int> a[maxn];
char s[maxn];
int dp[maxn];
int ans=0;
void dfs(int u,int p=-1) {
for(auto v:a[u]) if(v!=p) dfs(v,u);
int ad=0;
if(s[u]=='1') ad=1;
for(auto v:a[u]) if(v!=p) ans=max(ans,dp[v]+ad);
dp[u]=-ad;
for(auto v:a[u]) if(v!=p) dp[u]+=dp[v];
dp[u]=max(dp[u],ad);
ans=max(ans,dp[u]);
}
int main() {
int u,v;
scanf("%d",&n);
for(int i=0;i<n-1;i++) {
scanf("%d %d",&u,&v);
a[u].push_back(v);
a[v].push_back(u);
}
scanf("%s",s+1);
dfs(1);
printf("%d",ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |