Submission #473787

#TimeUsernameProblemLanguageResultExecution timeMemory
473787LainPower Plant (JOI20_power)C++17
100 / 100
212 ms34372 KiB
#include "bits/stdc++.h" using namespace std; template<class Fun> class y_combinator_result { Fun fun_; public: template<class T> explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {} template<class ...Args> decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward<Args>(args)...); } }; template<class Fun> decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<vector<int>> g(n); for (int i = 0; i < n-1; i++) { int u,v; cin >> u >> v; u--,v--; g[u].push_back(v); g[v].push_back(u); } string gen; cin >> gen; vector<int> dp(n); int ans = 0; y_combinator([&](auto self, int s, int p)->void { vector<int> c; for (auto& u : g[s]){ if (u==p) continue; self(u,s); c.push_back(dp[u]); } if (gen[s] == '0') { for (auto& x : c) dp[s] += x; } else { if (c.size() == 0) dp[s] = 1; else { ans = max(ans,*max_element(c.begin(),c.end())+1); for (auto& x : c) dp[s] += x; dp[s]--; dp[s] = max(dp[s],1); } } ans = max(dp[s],ans); })(0,-1); cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...