Submission #347393

#TimeUsernameProblemLanguageResultExecution timeMemory
347393dolphingarlicPower Plant (JOI20_power)C++14
100 / 100
192 ms27180 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; string s; vector<int> graph[200001]; int dp[200001], ans = 1; void dfs(int node = 1, int parent = 0) { int mx = 0; for (int i : graph[node]) if (i != parent) { dfs(i, node); dp[node] += dp[i]; mx = max(mx, dp[i]); } dp[node] = max(s[node - 1] - '0', dp[node] - s[node - 1] + '0'); ans = max(ans, max(mx + s[node - 1] - '0', dp[node])); } int main() { cin.tie(0)->sync_with_stdio(0); int n; cin >> n; for (int i = 1; i < n; i++) { int a, b; cin >> a >> b; graph[a].push_back(b); graph[b].push_back(a); } cin >> s; dfs(); cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...