Submission #715180

#TimeUsernameProblemLanguageResultExecution timeMemory
715180fdnfksdPower Plant (JOI20_power)C++14
100 / 100
179 ms29908 KiB
#include<bits/stdc++.h> #define TASKNAME "codeforce" #define pb push_back #define pli pair<int,int> #define fi first #define se second #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); using namespace std; using ll=long long; const ll maxN=3e5; const ll inf=1e18; const ll mod=1e9+7; ll ans=0; vector<ll>g[maxN]; ll dp[maxN]; string s; void dfs(ll u=1,ll p=0) { dp[u]=(s[u]=='1'); ll x=0; for(int v:g[u]) { if(v!=p) { dfs(v,u); x+=dp[v]; //dp[u]=max(dp[u],dp[v]); } } dp[u]=max(dp[u],x-(s[u]=='1')); ans=max(ans,dp[u]); for(int v:g[u]) { if(v!=p) { ans=max(ans,dp[v]+(s[u]=='1')); } } } ll n; void solve() { cin >> n; for(int i=1;i<n;i++) { ll u,v; cin >> u >> v ; g[u].pb(v); g[v].pb(u); } cin >> s; s=' '+s; dfs(); cout << ans; } int main() { fastio //freopen(TASKNAME".INP","r",stdin); //freopen(TASKNAME".OUT","w",stdout); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...