Submission #766003

#TimeUsernameProblemLanguageResultExecution timeMemory
766003Owen11Power Plant (JOI20_power)C++14
0 / 100
3 ms5024 KiB
#include <bits/stdc++.h> using namespace std; # define int long long # define fir first # define sec second # define pb push_back const int cnst = 2e5+5; bool mutipletestcase = 0; //bool debug = false; vector<int> vec[cnst]; bool id[cnst]; int par[cnst]; int counts[cnst]; int ans = 0; void dfs(int x) { int y = 0; int fre = 0; for(auto v: vec[x]) { if(v == par[x]) continue; par[v] = x; dfs(v); y += counts[v]; if(counts[v]) fre++; } if(!id[x]) counts[x] = y; else counts[x] = max(y-1, 1ll); if(fre == 1) ans = max(ans, y+id[x]); else ans = max(ans, y-id[x]); } void solve() { int n; cin >> n; for(int i = 1; i<n; i++) { int a, b; cin >> a >> b; vec[a].pb(b); vec[b].pb(a); } string s; cin >> s; for(int i = 0; i<n; i++) { id[i+1] = (s[i] == '1'); } dfs(1); cout << ans << endl; } signed main() { ios_base::sync_with_stdio(false); int t = 1; if(mutipletestcase) cin >> t; while(t--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...