Submission #899317

#TimeUsernameProblemLanguageResultExecution timeMemory
899317KeysPower Plant (JOI20_power)C++14
100 / 100
101 ms29596 KiB
#include <bits/stdc++.h> using namespace std; #define int int64_t typedef vector<int> vi; typedef pair<int, int> pi; typedef vector<pi> vpi; #define ar array #define all(x) x.begin(), x.end() #define pb push_back #define endl '\n' #define f first #define s second #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define ROF(i, a, b) for (int i = a; i >= b; i--) #define trav(i, a) for (auto& i : a) template <class T> istream &operator>>(istream& in, vector<T> &v) {trav(i, v) in >> i; return in;} #ifdef LOCAL #include "../../lib/debug.h" #else #define dbg(...) #endif const int N = 2e5 + 5; vi g[N]; int dp[N]; // no vertical path string s; int ans = 0; void dfs(int u, int p) { int sum = 0, mx = 0; trav(v, g[u]) if (v != p) { dfs(v, u); sum += dp[v]; mx = max(mx, dp[v]); } if (s[u] == '1') { ans = max(ans, max(sum - 1, mx + 1)); dp[u] = sum - 1; if (dp[u] < 1) dp[u] = 1; } else { ans = max(ans, sum); dp[u] = sum; } } signed main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; FOR(i, 0, n - 1) { int u, v; cin >> u >> v; g[u].pb(v); g[v].pb(u); } cin >> s; s = '$' + s; dfs(1, 0); cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...