답안 #947835

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
947835 2024-03-17T05:50:08 Z NeroZein Power Plant (JOI20_power) C++17
100 / 100
102 ms 29676 KB
#include "bits/stdc++.h"
using namespace std;

#ifdef Nero
#include "Deb.h"
#else
#define debug(...)
#endif

const int N = 2e5 + 5;

bool s[N];
int dp[N][2];
vector<int> g[N];

void dfs(int v, int p) {
  dp[v][0] = dp[v][1] = s[v];
  int sum = 0; 
  for (int u : g[v]) {
    if (u == p) continue; 
    dfs(u, v); 
    sum += dp[u][1];
    dp[v][0] = max(dp[v][0], dp[u][0]);
    dp[v][0] = max(dp[v][0], s[v] + dp[u][1]);
  }
  dp[v][0] = max(dp[v][0], sum - s[v]);
  dp[v][1] = max(dp[v][1], sum - s[v]); 
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  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);
  }
  for (int i = 1; i <= n; ++i) {
    char c;
    cin >> c;
    s[i] = c - '0';
  }
  dfs(1, 0);
  cout << dp[1][0] << '\n';
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 2 ms 6768 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 1 ms 6748 KB Output is correct
9 Correct 2 ms 6744 KB Output is correct
10 Correct 1 ms 6748 KB Output is correct
11 Correct 1 ms 6748 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 2 ms 6744 KB Output is correct
14 Correct 1 ms 6748 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 1 ms 6748 KB Output is correct
17 Correct 1 ms 6748 KB Output is correct
18 Correct 1 ms 6748 KB Output is correct
19 Correct 1 ms 6748 KB Output is correct
20 Correct 1 ms 6748 KB Output is correct
21 Correct 2 ms 6800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 2 ms 6768 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 1 ms 6748 KB Output is correct
9 Correct 2 ms 6744 KB Output is correct
10 Correct 1 ms 6748 KB Output is correct
11 Correct 1 ms 6748 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 2 ms 6744 KB Output is correct
14 Correct 1 ms 6748 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 1 ms 6748 KB Output is correct
17 Correct 1 ms 6748 KB Output is correct
18 Correct 1 ms 6748 KB Output is correct
19 Correct 1 ms 6748 KB Output is correct
20 Correct 1 ms 6748 KB Output is correct
21 Correct 2 ms 6800 KB Output is correct
22 Correct 2 ms 6748 KB Output is correct
23 Correct 2 ms 6748 KB Output is correct
24 Correct 2 ms 6748 KB Output is correct
25 Correct 2 ms 6748 KB Output is correct
26 Correct 2 ms 6748 KB Output is correct
27 Correct 2 ms 6748 KB Output is correct
28 Correct 2 ms 6748 KB Output is correct
29 Correct 2 ms 7004 KB Output is correct
30 Correct 2 ms 7000 KB Output is correct
31 Correct 2 ms 7004 KB Output is correct
32 Correct 3 ms 6748 KB Output is correct
33 Correct 2 ms 6748 KB Output is correct
34 Correct 3 ms 6744 KB Output is correct
35 Correct 2 ms 6748 KB Output is correct
36 Correct 2 ms 6748 KB Output is correct
37 Correct 2 ms 6748 KB Output is correct
38 Correct 2 ms 6748 KB Output is correct
39 Correct 2 ms 6748 KB Output is correct
40 Correct 2 ms 6748 KB Output is correct
41 Correct 2 ms 6748 KB Output is correct
42 Correct 2 ms 6748 KB Output is correct
43 Correct 2 ms 6748 KB Output is correct
44 Correct 2 ms 6748 KB Output is correct
45 Correct 2 ms 6748 KB Output is correct
46 Correct 2 ms 6748 KB Output is correct
47 Correct 2 ms 6748 KB Output is correct
48 Correct 2 ms 6748 KB Output is correct
49 Correct 2 ms 7000 KB Output is correct
50 Correct 2 ms 6748 KB Output is correct
51 Correct 2 ms 6748 KB Output is correct
52 Correct 2 ms 6748 KB Output is correct
53 Correct 2 ms 6748 KB Output is correct
54 Correct 2 ms 6748 KB Output is correct
55 Correct 2 ms 6748 KB Output is correct
56 Correct 2 ms 6888 KB Output is correct
57 Correct 2 ms 7000 KB Output is correct
58 Correct 2 ms 6748 KB Output is correct
59 Correct 2 ms 6748 KB Output is correct
60 Correct 3 ms 6748 KB Output is correct
61 Correct 2 ms 6748 KB Output is correct
62 Correct 2 ms 6744 KB Output is correct
63 Correct 2 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 2 ms 6768 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 1 ms 6748 KB Output is correct
9 Correct 2 ms 6744 KB Output is correct
10 Correct 1 ms 6748 KB Output is correct
11 Correct 1 ms 6748 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 2 ms 6744 KB Output is correct
14 Correct 1 ms 6748 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 1 ms 6748 KB Output is correct
17 Correct 1 ms 6748 KB Output is correct
18 Correct 1 ms 6748 KB Output is correct
19 Correct 1 ms 6748 KB Output is correct
20 Correct 1 ms 6748 KB Output is correct
21 Correct 2 ms 6800 KB Output is correct
22 Correct 2 ms 6748 KB Output is correct
23 Correct 2 ms 6748 KB Output is correct
24 Correct 2 ms 6748 KB Output is correct
25 Correct 2 ms 6748 KB Output is correct
26 Correct 2 ms 6748 KB Output is correct
27 Correct 2 ms 6748 KB Output is correct
28 Correct 2 ms 6748 KB Output is correct
29 Correct 2 ms 7004 KB Output is correct
30 Correct 2 ms 7000 KB Output is correct
31 Correct 2 ms 7004 KB Output is correct
32 Correct 3 ms 6748 KB Output is correct
33 Correct 2 ms 6748 KB Output is correct
34 Correct 3 ms 6744 KB Output is correct
35 Correct 2 ms 6748 KB Output is correct
36 Correct 2 ms 6748 KB Output is correct
37 Correct 2 ms 6748 KB Output is correct
38 Correct 2 ms 6748 KB Output is correct
39 Correct 2 ms 6748 KB Output is correct
40 Correct 2 ms 6748 KB Output is correct
41 Correct 2 ms 6748 KB Output is correct
42 Correct 2 ms 6748 KB Output is correct
43 Correct 2 ms 6748 KB Output is correct
44 Correct 2 ms 6748 KB Output is correct
45 Correct 2 ms 6748 KB Output is correct
46 Correct 2 ms 6748 KB Output is correct
47 Correct 2 ms 6748 KB Output is correct
48 Correct 2 ms 6748 KB Output is correct
49 Correct 2 ms 7000 KB Output is correct
50 Correct 2 ms 6748 KB Output is correct
51 Correct 2 ms 6748 KB Output is correct
52 Correct 2 ms 6748 KB Output is correct
53 Correct 2 ms 6748 KB Output is correct
54 Correct 2 ms 6748 KB Output is correct
55 Correct 2 ms 6748 KB Output is correct
56 Correct 2 ms 6888 KB Output is correct
57 Correct 2 ms 7000 KB Output is correct
58 Correct 2 ms 6748 KB Output is correct
59 Correct 2 ms 6748 KB Output is correct
60 Correct 3 ms 6748 KB Output is correct
61 Correct 2 ms 6748 KB Output is correct
62 Correct 2 ms 6744 KB Output is correct
63 Correct 2 ms 6748 KB Output is correct
64 Correct 68 ms 15992 KB Output is correct
65 Correct 62 ms 15952 KB Output is correct
66 Correct 66 ms 15992 KB Output is correct
67 Correct 66 ms 15988 KB Output is correct
68 Correct 87 ms 15824 KB Output is correct
69 Correct 64 ms 15984 KB Output is correct
70 Correct 59 ms 15952 KB Output is correct
71 Correct 80 ms 15972 KB Output is correct
72 Correct 69 ms 15952 KB Output is correct
73 Correct 82 ms 28436 KB Output is correct
74 Correct 84 ms 28496 KB Output is correct
75 Correct 63 ms 15688 KB Output is correct
76 Correct 59 ms 15708 KB Output is correct
77 Correct 61 ms 15700 KB Output is correct
78 Correct 61 ms 15876 KB Output is correct
79 Correct 102 ms 15696 KB Output is correct
80 Correct 74 ms 15696 KB Output is correct
81 Correct 55 ms 16076 KB Output is correct
82 Correct 59 ms 15896 KB Output is correct
83 Correct 76 ms 21076 KB Output is correct
84 Correct 92 ms 23048 KB Output is correct
85 Correct 70 ms 22880 KB Output is correct
86 Correct 74 ms 17232 KB Output is correct
87 Correct 72 ms 16744 KB Output is correct
88 Correct 80 ms 17116 KB Output is correct
89 Correct 72 ms 17472 KB Output is correct
90 Correct 61 ms 16976 KB Output is correct
91 Correct 68 ms 17044 KB Output is correct
92 Correct 60 ms 17492 KB Output is correct
93 Correct 83 ms 19892 KB Output is correct
94 Correct 94 ms 21420 KB Output is correct
95 Correct 60 ms 20176 KB Output is correct
96 Correct 63 ms 18592 KB Output is correct
97 Correct 63 ms 17028 KB Output is correct
98 Correct 69 ms 16520 KB Output is correct
99 Correct 67 ms 16212 KB Output is correct
100 Correct 62 ms 19284 KB Output is correct
101 Correct 62 ms 17476 KB Output is correct
102 Correct 61 ms 16724 KB Output is correct
103 Correct 65 ms 16528 KB Output is correct
104 Correct 58 ms 16760 KB Output is correct
105 Correct 77 ms 25372 KB Output is correct
106 Correct 43 ms 16376 KB Output is correct
107 Correct 47 ms 16400 KB Output is correct
108 Correct 102 ms 29352 KB Output is correct
109 Correct 57 ms 16768 KB Output is correct
110 Correct 102 ms 29676 KB Output is correct
111 Correct 57 ms 15692 KB Output is correct