답안 #817951

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
817951 2023-08-09T21:22:08 Z tch1cherin Power Plant (JOI20_power) C++17
0 / 100
3 ms 5028 KB
#include <bits/stdc++.h>
using namespace std;
 
const int MAX_N = 2e5 + 5;
vector<int> G[MAX_N];
int dp[MAX_N] = {};
string S;
int ans;
 
void DFS(int u, int p) {
  if (S[u] == '0') {
    for (int v : G[u]) {
      if (v != p) {
        DFS(v, u);
        dp[u] += dp[v];
      }
    }
    ans = max(ans, dp[u]);
  } else {
    for (int v : G[u]) {
      if (v != p) {
        DFS(v, u);
        ans = max(ans, dp[v] + 1);
        dp[u] += dp[v];
      }
    }
    ans = max(ans, dp[u]);
    if (dp[u] > 1) {
      dp[u] -= 1;
    }
    if (dp[u] == 0) {
      dp[u] += 1;
    }
  }
}
 
int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int N;
  cin >> N;
  for (int i = 0; i < N - 1; i++) {
    int A, B;
    cin >> A >> B;
    A--, B--;
    G[A].push_back(B);
    G[B].push_back(A);
  }
  cin >> S;
  ans = 1;
  DFS(0, -1);
  cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 3 ms 5024 KB Output is correct
5 Correct 2 ms 4948 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 2 ms 4948 KB Output is correct
12 Incorrect 2 ms 5028 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 3 ms 5024 KB Output is correct
5 Correct 2 ms 4948 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 2 ms 4948 KB Output is correct
12 Incorrect 2 ms 5028 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 3 ms 5024 KB Output is correct
5 Correct 2 ms 4948 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 2 ms 4948 KB Output is correct
12 Incorrect 2 ms 5028 KB Output isn't correct
13 Halted 0 ms 0 KB -