Submission #473789

#TimeUsernameProblemLanguageResultExecution timeMemory
473789LainPower Plant (JOI20_power)C++17
100 / 100
189 ms26176 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 { for (auto& u : g[s]){ if (u==p) continue; self(u,s); dp[s] += dp[u]; if (gen[s] == '1') ans = max(ans,dp[u] + 1); } if (gen[s] == '1') dp[s] = max(dp[s]-1,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...