답안 #862430

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
862430 2023-10-18T08:29:40 Z Desh03 Power Plant (JOI20_power) C++17
0 / 100
2 ms 6492 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5;
vector<int> g[N];
string s;
int dp[2][N];

void dfs(int u, int p) {
    dp[0][u] = dp[1][u] = s[u];
    int sum_dp = 0, mx_dp = 0;
    for (int v : g[u]) {
        if (v != p) {
            dfs(v, u);
            dp[0][u] = max(dp[0][u], dp[0][v]);
            sum_dp += dp[1][v];
            mx_dp = max(mx_dp, dp[1][v]);
        }
    }
    dp[0][u] = max({dp[0][u], sum_dp, mx_dp + s[u]});
    dp[1][u] = max(dp[1][u], sum_dp - s[u]);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        g[--a].push_back(--b);
        g[b].push_back(a);
    }
    cin >> s;
    for (char &c : s) c -= '0';
    dfs(0, 0);
    cout << dp[0][0] << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6316 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
12 Incorrect 2 ms 6492 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6316 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
12 Incorrect 2 ms 6492 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6316 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
12 Incorrect 2 ms 6492 KB Output isn't correct
13 Halted 0 ms 0 KB -