Submission #493633

# Submission time Handle Problem Language Result Execution time Memory
493633 2021-12-12T12:42:02 Z 600Mihnea Power Plant (JOI20_power) C++17
0 / 100
4 ms 5020 KB
#include <bits/stdc++.h>

using namespace std;

const int N = (int) 2e5 + 7;
int n;
int sol;
int dp[N];
bool is[N];
vector<int> g[N];
string s;

void build(int a, int p = -1) {
  dp[a] = 0;
  for (auto &b : g[a]) {
    if (b != p) {
      build(b, a);
      dp[a] += dp[b];
    }
  }
  dp[a] -= is[a];
  dp[a] = max(dp[a], (int) is[a]);
}
int main() {
  ios::sync_with_stdio(0); cin.tie(0);

  ///freopen ("input.txt", "r", stdin);

  cin >> n;
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  cin >> s;
  for (int i = 1; i <= n; i++) {
    is[i] = s[i - 1] - '0';
  }
  for (int i = 1; i <= n; i++) {
    build(i);
    sol = max(sol, dp[i]);
  }
  cout << sol << "\n";

  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 2 ms 4940 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 4 ms 5020 KB Output is correct
6 Correct 2 ms 5020 KB Output is correct
7 Correct 3 ms 4944 KB Output is correct
8 Incorrect 3 ms 4944 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 2 ms 4940 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 4 ms 5020 KB Output is correct
6 Correct 2 ms 5020 KB Output is correct
7 Correct 3 ms 4944 KB Output is correct
8 Incorrect 3 ms 4944 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 2 ms 4940 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 4 ms 5020 KB Output is correct
6 Correct 2 ms 5020 KB Output is correct
7 Correct 3 ms 4944 KB Output is correct
8 Incorrect 3 ms 4944 KB Output isn't correct
9 Halted 0 ms 0 KB -