Submission #868670

#TimeUsernameProblemLanguageResultExecution timeMemory
868670sleepntsheepPower Plant (JOI20_power)C++17
0 / 100
1 ms6492 KiB
#include <cstdio> #include <cstring> #include <cassert> #include <string> #include <deque> #include <vector> #include <map> #include <queue> #include <algorithm> #include <iostream> #include <utility> using namespace std; using ll = long long; using ld = long double; #define ShinLena cin.tie(nullptr)->sync_with_stdio(false) #define N 200005 #define ALL(x) x.begin(), x.end() int n, ans, f[N], h[N], pwr[N]; vector<int> g[N]; char s[N]; void dfs(int u, int p) { if (s[u]=='1')++pwr[u], f[u]=h[u]=1; int C=0; for (auto v : g[u]) if (v^p) { dfs(v, u); pwr[u] += pwr[v]; C+=!!pwr[v]; f[u]+=f[v]; } ans=max(ans,f[u]); if (s[u]=='1') { f[u]=max(f[u]-1, 1); } h[u] = max(C+1, 1); } int main() { ShinLena; cin >> n; for (int i = 1, u, v; i < n; ++i) cin >> u >> v, g[u].push_back(v), g[v].push_back(u); cin >> (s+1); dfs(1, 1); cout<<ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...