Submission #787147

#TimeUsernameProblemLanguageResultExecution timeMemory
787147Rafi22Power Plant (JOI20_power)C++14
100 / 100
111 ms28796 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define st first #define nd second #define pb push_back #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() #define ll long long ll mod=1000000007; int inf=1000000007; ll infl=1000000000000000007; const int N=200007; vector<int>G[N]; string s; int DP[N]; int ans; void dfs(int v,int o) { if(s[v]=='1') DP[v]=-1; for(auto u:G[v]) { if(u==o) continue; dfs(u,v); DP[v]+=DP[u]; } if(s[v]=='1') DP[v]=max(DP[v],1); ans=max(ans,DP[v]); if(s[o]=='1') ans=max(ans,DP[v]+1); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n; for(int i=1;i<n;i++) { int a,b; cin>>a>>b; G[a].pb(b); G[b].pb(a); } cin>>s; s='#'+s; dfs(1,0); cout<<ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...