# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
394363 | parsabahrami | Power Plant (JOI20_power) | C++17 | 3 ms | 4940 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* There's someone in my head but it's not me */
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
#define SZ(x) (int) x.size()
#define F first
#define S second
const int N = 2e5 + 10, MOD = 1e9 + 7;
int dp[N], pd[N], M[N], n, rt; vector<int> adj[N];
int ret = 0;
void DFS(int v, int p = -1) {
for (int u : adj[v])
if (u != p) DFS(u, v);
int sum = 0;
for (int u : adj[v])
if (u != p) sum += dp[u];
for (int u : adj[v])
if (u != p)
dp[v] = max(dp[v], dp[u] - M[v]);
dp[v] = max(dp[v], sum - M[v]);
dp[v] = max(dp[v], M[v]);
if (~p) ret = max(ret, dp[v] + M[p]);
//printf("%d %d\n", v, dp[v]);
}
int main() {
scanf("%d", &n);
for (int i = 1; i < n; i++) {
int u, v; scanf("%d%d", &u, &v);
adj[u].push_back(v);
adj[v].push_back(u);
}
scanf("\n");
for (int i = 1; i <= n; i++) {
char c; scanf("%c", &c);
if (c - '0') M[i] = 1, rt = i;
}
DFS(rt);
printf("%d\n", ret);
return 0;
}
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... |