| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1299174 | khoile08 | Power Plant (JOI20_power) | C++20 | 153 ms | 25940 KiB |
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FOD(i, a, b) for(int i = a; i >= b; i--)
//#define int long long
#define fi first
#define se second
#define ll long long
#define db double
#define pb push_back
#define ii pair<int,int>
#define sq(i) (1LL * (i) * (i))
#define MASK(i) (1LL << i)
#define task "task"
const int inf = 1e9;
const ll INF = 1e18;
const int N = 2e5 + 4;
int n, res;
vector<int> g[N];
bool ch[N];
int dp[N];
void dfs(int u, int p) {
for(int v : g[u]) {
if(v == p) continue;
dfs(v, u);
dp[u] += dp[v];
res = max(res, dp[v] + ch[u]);
}
dp[u] -= ch[u];
dp[u] = max(dp[u], (int)ch[u]);
}
signed main() {
if(fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
FOR(i, 1, n - 1) {
int u, v;
cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
FOR(i, 1, n) {
char c;
cin >> c;
ch[i] = (c == '1');
}
dfs(1, -1);
FOR(i, 1, n) res = max(res, dp[i]);
cout << res << '\n';
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
