Submission #502467

#TimeUsernameProblemLanguageResultExecution timeMemory
502467tengiz05Power Plant (JOI20_power)C++17
0 / 100
4 ms5020 KiB
#include <bits/stdc++.h> using i64 = long long; constexpr int N = 200000; int n; std::vector<int> e[N]; int a[N], dp[N]; void dfs(int u, int p) { int sum = 0; for (int v : e[u]) { if (v != p) { dfs(v, u); sum += dp[v]; } } dp[u] = std::max(a[u], sum - a[u]); } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cin >> n; for (int i = 0; i < n - 1; i++) { int u, v; std::cin >> u >> v; u--; v--; e[u].push_back(v); e[v].push_back(u); } std::string S; std::cin >> S; for (int i = 0; i < n; i++) { a[i] = S[i] - '0'; } int ans = 0; for (int i = 0; i < n; i++) { dfs(i, -1); ans = std::max(ans, dp[i]); } std::cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...