Submission #532741

# Submission time Handle Problem Language Result Execution time Memory
532741 2022-03-03T19:33:45 Z Alex_tz307 Power Plant (JOI20_power) C++17
0 / 100
3 ms 4940 KB
#include <bits/stdc++.h>

using namespace std;

const int kN = 2e5;
vector<int> g[1 + kN];
string s;
int dp[1 + kN];

void maxSelf(int &x, int y) {
  if (x < y) {
    x = y;
  }
}

void dfs(int u, int par) {
  dp[u] = s[u] - '0';
  int sum = 0;
  for (int v : g[u]) {
    if (v != par) {
      dfs(v, u);
      sum += dp[v];
    }
  }
  maxSelf(dp[u], sum - (par && (s[u] - '0')));
}

void testCase() {
  int n;
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    g[u].emplace_back(v);
    g[v].emplace_back(u);
  }
  cin >> s;
  s = '$' + s;
  int ans = 0;
  for (int v = 1; v <= n; ++v) {
    dfs(v, 0);
    maxSelf(ans, dp[v]);
  }
  cout << ans << '\n';
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int tests = 1;
  for (int tc = 0; tc < tests; ++tc) {
    testCase();
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 2 ms 4940 KB Output is correct
5 Incorrect 3 ms 4940 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 2 ms 4940 KB Output is correct
5 Incorrect 3 ms 4940 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 2 ms 4940 KB Output is correct
5 Incorrect 3 ms 4940 KB Output isn't correct
6 Halted 0 ms 0 KB -