Submission #645021

#TimeUsernameProblemLanguageResultExecution timeMemory
645021Markomafko972Power Plant (JOI20_power)C++14
6 / 100
4 ms5080 KiB
#include <bits/stdc++.h> #define X first #define Y second #define pb push_back #define pii pair<int, int> typedef long long ll; using namespace std; const int MOD = 1e9 + 7; const ll INF = 1e18; const int OFF = (1 << 20); int n, a, b, sol = 0; char c; vector<int> v[200005]; int val[200005]; int rek(int x, int prt) { int tren = 0, koldj = 0; for (int i = 0; i < (int)v[x].size(); i++) { if (prt == v[x][i]) continue; int sad = rek(v[x][i], x); tren += sad; if (sad > 0) koldj++; } if (val[x] == 0) { sol = max(sol, tren); return tren; } else { if (koldj > 1) sol = max(sol, tren-1); else sol = max(sol, tren+1); return max(tren-1, 1); } } int main () { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 0; i < n-1; i++) { cin >> a >> b; v[a].push_back(b); v[b].push_back(a); } for (int i = 1; i <= n; i++) { cin >> c; val[i] = c - '0'; } rek(1, 0); cout << sol; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...