Submission #914053

#TimeUsernameProblemLanguageResultExecution timeMemory
914053OAleksaPower Plant (JOI20_power)C++14
100 / 100
213 ms31776 KiB
#include <bits/stdc++.h> //ako ovaj vaso daso misli da me pobedjuje..... using namespace std; #define int long long #define f first #define s second const int N = 2e5 + 69; int n, mark[N], dp[N], up[N]; vector<int> g[N]; string s; void dfs(int v, int p) { for (auto u : g[v]) { if (u == p) continue; dfs(u, v); dp[v] += dp[u]; } dp[v] -= mark[v]; if (mark[v]) dp[v] = max(dp[v], 1ll); } int ans = 0; void dfs1(int v, int p) { ans = max(ans, dp[v]); for (auto u : g[v]) { if (u == p) continue; dfs1(u, v); ans = max(ans, dp[u] + mark[v]); } } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int tt = 1; //cin >> tt; while (tt--) { cin >> n; for (int i = 1;i <= n - 1;i++) { int a, b; cin >> a >> b; g[a].push_back(b); g[b].push_back(a); } cin >> s; for (int i = 0;i < n;i++) { if (s[i] == '1') mark[i + 1] = 1; } dfs(1, 0); dfs1(1, 0); cout << ans; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...