Submission #418767

#TimeUsernameProblemLanguageResultExecution timeMemory
418767MohamedAhmed04Power Plant (JOI20_power)C++14
100 / 100
236 ms29252 KiB
#include <bits/stdc++.h> using namespace std ; const int MAX = 2e5 + 10 ; int n ; int mark[MAX] ; vector< vector<int> >adj(MAX) ; int ans = 0 ; int dp[MAX] ; void dfs(int node , int par) { int cnt = 0 ; for(auto &child : adj[node]) { if(child == par) continue ; dfs(child , node) ; cnt += dp[child] ; if(mark[node]) ans = max(ans , dp[child] + 1) ; } if(mark[node]) dp[node] = max(1 , cnt - 1) ; else dp[node] = cnt ; ans = max(ans , dp[node]) ; } int main() { ios_base::sync_with_stdio(0) ; cin.tie(0) ; cin>>n ; for(int i = 0 ; i < n-1 ; ++i) { int x , y ; cin>>x>>y ; adj[x].push_back(y) ; adj[y].push_back(x) ; } for(int i = 1 ; i <= n ; ++i) { char c ; cin>>c ; mark[i] = (c - '0') ; } dfs(1 , -1) ; return cout<<ans<<"\n" , 0 ; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...