Submission #763312

#TimeUsernameProblemLanguageResultExecution timeMemory
763312vjudge1Power Plant (JOI20_power)C++17
47 / 100
4 ms5076 KiB
#include<bits/stdc++.h> using namespace std; int n, x, y, ans = 0, dp[100001]; vector<int> vec[100001]; string s; bool visited[100001]; void dfs(int x) { int maxi = 0; visited[x] = true; for(int c : vec[x]) { if(!visited[c]) { dfs(c); dp[x] += dp[c]; maxi = max(dp[c], maxi); } } dp[x] = max(s[x - 1] - '0', dp[x] - s[x - 1] + '0'); ans = max(ans, max(maxi + s[x - 1] - '0', dp[x])); } int main() { cin >> n; for(int i = 1; i < n; ++i) { cin >> x >> y; vec[x].push_back(y); vec[y].push_back(x); } cin >> s; dfs(n); cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...