Submission #813126

#TimeUsernameProblemLanguageResultExecution timeMemory
813126gun_ganPower Plant (JOI20_power)C++17
100 / 100
134 ms28792 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MX = 2e5 + 5; int N; vector<int> g[MX]; int dp[MX]; int ans = 0; string s; void dfs(int v, int p) { int cur = 0, mx = 0; // cur = ambil >= 1, mx = ambil 1 yg maksimum for(auto u : g[v]) { if(u == p) continue; dfs(u, v); cur += max(0, dp[u]); mx = max(mx, dp[u]); } if(s[v] == '1') { dp[v] = max(1, cur - 1); ans = max(ans, cur - 1); ans = max(ans, mx + 1); // consider subtree ini aja } else { dp[v] = cur; ans = max(ans, cur); } } int main() { cin.tie(0); ios_base::sync_with_stdio(0); cin >> N; for(int i = 0; i < N - 1; i++) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } cin >> s; s = '#' + s; dfs(1, 0); cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...