Submission #818537

#TimeUsernameProblemLanguageResultExecution timeMemory
818537vjudge1Power Plant (JOI20_power)C++17
100 / 100
135 ms28988 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const int N = 2e5 + 10; vector<int> g[N]; int dp[N]; int n; string s; int res; void dfs(int v, int p) { int sum = 0, mx = 0; for(int to : g[v]) { if(to == p) continue; dfs(to, v); mx = max(mx, dp[to]); sum += max(dp[to], 0); } dp[v] = max(s[v - 1] - '0', sum - (s[v - 1] - '0')); res = max(res, dp[v]); if(s[v - 1] == '1') res = max(res, mx + 1); } int main() { ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); cin >> n; for(int i = 1; i < n; i++) { int a, b; cin >> a >> b; g[a].push_back(b); g[b].push_back(a); } cin >> s; dfs(1, 1); // for(int i = 1; i <= n; i++) { // cout << dp[i] << ' '; // } // cout << '\n'; cout << res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...