Submission #347391

# Submission time Handle Problem Language Result Execution time Memory
347391 2021-01-12T19:42:48 Z dolphingarlic Power Plant (JOI20_power) C++14
0 / 100
4 ms 5248 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

string s;
vector<int> graph[200001];
int dp[200001], ans = 1;

void dfs(int node = 1, int parent = 0) {
    int cnt = 0;
    for (int i : graph[node]) if (i != parent) {
        dfs(i, node);
        dp[node] += dp[i];
        if (dp[i]) cnt++;
    }
    ans = max(ans, dp[node] + (s[node - 1] == '1' && cnt < 2));
    dp[node] = max(s[node - 1] - '0', dp[node] - s[node - 1] + '0');
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int n;
    cin >> n;
    for (int i = 1; i < n; i++) {
        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    cin >> s;
    dfs();
    cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4972 KB Output is correct
2 Correct 3 ms 5116 KB Output is correct
3 Correct 3 ms 4972 KB Output is correct
4 Correct 3 ms 4972 KB Output is correct
5 Correct 3 ms 4972 KB Output is correct
6 Correct 3 ms 5248 KB Output is correct
7 Correct 3 ms 4972 KB Output is correct
8 Correct 4 ms 4972 KB Output is correct
9 Correct 3 ms 4972 KB Output is correct
10 Correct 4 ms 4972 KB Output is correct
11 Correct 3 ms 4972 KB Output is correct
12 Incorrect 3 ms 4972 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4972 KB Output is correct
2 Correct 3 ms 5116 KB Output is correct
3 Correct 3 ms 4972 KB Output is correct
4 Correct 3 ms 4972 KB Output is correct
5 Correct 3 ms 4972 KB Output is correct
6 Correct 3 ms 5248 KB Output is correct
7 Correct 3 ms 4972 KB Output is correct
8 Correct 4 ms 4972 KB Output is correct
9 Correct 3 ms 4972 KB Output is correct
10 Correct 4 ms 4972 KB Output is correct
11 Correct 3 ms 4972 KB Output is correct
12 Incorrect 3 ms 4972 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4972 KB Output is correct
2 Correct 3 ms 5116 KB Output is correct
3 Correct 3 ms 4972 KB Output is correct
4 Correct 3 ms 4972 KB Output is correct
5 Correct 3 ms 4972 KB Output is correct
6 Correct 3 ms 5248 KB Output is correct
7 Correct 3 ms 4972 KB Output is correct
8 Correct 4 ms 4972 KB Output is correct
9 Correct 3 ms 4972 KB Output is correct
10 Correct 4 ms 4972 KB Output is correct
11 Correct 3 ms 4972 KB Output is correct
12 Incorrect 3 ms 4972 KB Output isn't correct
13 Halted 0 ms 0 KB -