Submission #813120

# Submission time Handle Problem Language Result Execution time Memory
813120 2023-08-07T13:42:09 Z gun_gan Power Plant (JOI20_power) C++17
0 / 100
3 ms 5028 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MX = 2e5 + 5;

int N;
vector<int> g[MX];
int dp[MX];
int ans = 0;
string s;

void dfs(int v, int p) {
      int cur = 0, mx = 0; // cur = ambil >= 1, mx = ambil 1 yg maksimum
      for(auto u : g[v]) {
            if(u == p) continue;

            dfs(u, v);
            cur += max(0, dp[u]);
            mx = max(mx, dp[u]);
      }

      if(s[v] == '1') {
            dp[v] = max(1, cur - 1); 

            ans = max(ans, cur); // consider subtree ini aja
            ans = max(ans, mx + 1);
      } else {
            dp[v] = cur;
            ans = max(ans, cur);
      }
}

int main() {
      cin.tie(0); ios_base::sync_with_stdio(0);

      cin >> N;
      for(int i = 0; i < N - 1; i++) {
            int u, v;
            cin >> u >> v;
            g[u].push_back(v);
            g[v].push_back(u);
      }

      cin >> s;
      s = '#' + s;

      dfs(1, 0);
      cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 5028 KB Output is correct
5 Correct 3 ms 5024 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Incorrect 2 ms 4948 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 5028 KB Output is correct
5 Correct 3 ms 5024 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Incorrect 2 ms 4948 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 5028 KB Output is correct
5 Correct 3 ms 5024 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Incorrect 2 ms 4948 KB Output isn't correct
13 Halted 0 ms 0 KB -