# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
868665 | 2023-11-01T09:50:16 Z | prohacker | Power Plant (JOI20_power) | C++14 | 0 ms | 348 KB |
#include <bits/stdc++.h> #define ll long long #define ld long double using namespace std; const int N = 5010; const int INF = INT_MAX; const int mod = 1e9+7; int n,ans,dp[N]; vector<int> adj[N]; string s; void dfs(int u, int pre) { dp[u] = 0; int res = 0; for(int v:adj[u]) { if(v == pre) { continue; } dfs(v,u); res += dp[v]; } dp[u] = max(res-(s[u] == '1'),(s[u] == '1' ? 1 : 0)); if(pre == 0) { int cnt = 0; for(int v:adj[u]) { if(dp[v]) { cnt++; } } if(cnt < 2) { dp[u]++; } ans = max(ans,dp[u]); } } signed main() { if (fopen("power.inp", "r")) { freopen("power.inp", "r", stdin); freopen("power.out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for(int i = 1 ; i < n ; i++) { int u,v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } cin >> s; s = " " + s; for(int i = 1 ; i <= n ; i++) { if(s[i] == '1') { dfs(i,0); } } cout << ans; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |