Submission #639993

#TimeUsernameProblemLanguageResultExecution timeMemory
639993colossal_pepePower Plant (JOI20_power)C++17
0 / 100
1 ms212 KiB
#include <iostream> #include <vector> #include <map> using namespace std; int n; vector<pair<int, int>> edges; vector<vector<int>> g; vector<map<int, int>> dp; string s; int dfs(int u, int par) { if (dp[u].find(par) != dp[u].end()) return dp[u][par]; int ret = 0; for (int v : g[u]) { if (v != par) ret += dfs(v, u); } if (s[u] == '1') ret = max(1, ret - 1); dp[u][par] = ret; return ret; } int solve() { dp.resize(n); int ans = 0; for (auto [a, b] : edges) { ans = max(ans, dfs(a, b) + dfs(b, a)); } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; edges.resize(n - 1), g.resize(n); for (auto &[a, b] : edges) { cin >> a >> b; a--, b--; g[a].push_back(b); g[b].push_back(a); } cin >> s; cout << solve() << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...