Submission #478386

#TimeUsernameProblemLanguageResultExecution timeMemory
478386jesus_coconutPower Plant (JOI20_power)C++17
100 / 100
210 ms28064 KiB
#include <bits/stdc++.h> #define F first #define S second #define all(a) begin(a), end(a) using namespace std; int const N = 200005; int n; vector<int> adj[N]; string s; void input() { cin >> n; for (int i = 0; i < n - 1; ++i) { int a, b; cin >> a >> b; --a; --b; adj[a].push_back(b); adj[b].push_back(a); } cin >> s; } int ans = 0; int dp(int ver, int par) { int ret = s[ver] == '1'; int suma = 0; for (auto u : adj[ver]) if (u != par) { int a = dp(u, ver); if (a > 0) suma += a; if (s[ver] == '1') { ans = max(ans, a + 1); } } ret = max(ret, suma - (s[ver] == '1')); ans = max(ans, ret); return ret; } void solve() { dp(0, -1); cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); input(); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...