Submission #623060

#TimeUsernameProblemLanguageResultExecution timeMemory
623060MahdiPower Plant (JOI20_power)C++17
100 / 100
183 ms32444 KiB
#include<bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; #define all(v) v.begin(), v.end() #define F first #define S second typedef long long ll; typedef pair<int, int> pii; const int N=2e5+5; int n, dp[N], pd[N]; vector<int>g[N]; string s; void dfs(const int &v, const int &p=-1){ for(int u: g[v]){ if(u!=p){ dfs(u, v); pd[v]+=pd[u]; if(s[v]=='1') dp[v]=max(dp[v], pd[u]+1); dp[v]=max(dp[v], dp[u]); } } if(s[v]=='1'){ --pd[v]; pd[v]=max(pd[v], 1); } dp[v]=max(dp[v], pd[v]); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin>>n; for(int i=1;i<n;++i){ int u, v; cin>>u>>v; g[--u].push_back(--v); g[v].push_back(u); } cin>>s; dfs(0); cout<<dp[0]<<'\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...