Submission #1053778

# Submission time Handle Problem Language Result Execution time Memory
1053778 2024-08-11T17:28:13 Z Sharky Power Plant (JOI20_power) C++17
0 / 100
1 ms 6748 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 200005;
int n, dp[N], s[N], pa[N], ans = 1;
vector<int> adj[N];

void dfs(int u, int p) {
    for (int v : adj[u]) {
        if (v == p) continue;
        pa[v] = u;
        dfs(v, u);
        dp[u] += max(s[v], dp[v]);
    }
    ans = max(ans, dp[u] + s[u]);
    dp[u] -= s[u];
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for (int i = 1; i < n; i++) {
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    for (int i = 1; i <= n; i++) {
        char c;
        cin >> c;
        s[i] = c - '0';
    }
    dfs(1, -1);
    for (int i = 2; i <= n; i++) ans = max(ans, s[pa[i]] + dp[i]);
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Incorrect 1 ms 6748 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Incorrect 1 ms 6748 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Incorrect 1 ms 6748 KB Output isn't correct
8 Halted 0 ms 0 KB -