Submission #539008

#TimeUsernameProblemLanguageResultExecution timeMemory
539008ddy888Power Plant (JOI20_power)C++17
100 / 100
183 ms32324 KiB
#undef _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define pb push_back #define fi first #define si second #define ar array using lint = long long; typedef pair<int,int> pi; typedef tuple<int,int,int> ti; void debug_out() {cerr<<endl;} template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr<<" "<<to_string(H);debug_out(T...);} #define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__) int N, ans; vector<int> adj[200010]; char S[200010]; int dp[200010][2]; void dfs(int x, int p) { int sum = 0, mx = 0; for (auto i: adj[x]) { if (i == p) continue; dfs(i, x); sum += dp[i][0]; mx = max(mx, dp[i][0]); } if (S[x] == '1') { dp[x][1] = max(mx + 1, 1); dp[x][0] = max(sum - 1, 1); } else { dp[x][0] = sum; dp[x][1] = sum; } } int main() { fast; cin >> N; for (int i = 1; i < N; ++i) { int u, v; cin >> u >> v; adj[u].pb(v); adj[v].pb(u); } for (int i = 1; i <= N; ++i) cin >> S[i]; dfs(1, -1); for (int i = 1; i <= N; ++i) ans = max({ans, dp[i][0], dp[i][1]}); cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...