답안 #908601

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
908601 2024-01-16T15:02:01 Z arashMLG Power Plant (JOI20_power) C++17
100 / 100
266 ms 41372 KB
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int N=5e5+23;int n,dp[N][2],is[N];vector<int> G[N];void dfs(int v,int p=-1) {int sum0=0,sum1=0,mx1=0,mx0=0;for(int u:G[v]) if(u!=p) {dfs(u,v);sum0+=dp[u][0];sum1+=dp[u][1];mx1=max(mx1,dp[u][1]);mx0=max(mx0,dp[u][0]);}dp[v][0]=(is[v]?max({mx0,sum1-1,1+mx1}):max({mx0,sum1}));dp[v][1]=(is[v]?max({1,sum1-1}):sum1);}int main(){cin>>n;for(int i=1; i<n ; i++) {int v,u;cin>>v>>u;G[v].pb(u);G[u].pb(v);}for(int i=1;i<=n;i++) {char c; cin>>c;is[i]=(c=='1');}dfs(1);cout<<dp[1][0]<<'\n';}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 14940 KB Output is correct
2 Correct 5 ms 15188 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
4 Correct 4 ms 14940 KB Output is correct
5 Correct 4 ms 14940 KB Output is correct
6 Correct 4 ms 14940 KB Output is correct
7 Correct 4 ms 14936 KB Output is correct
8 Correct 4 ms 14940 KB Output is correct
9 Correct 4 ms 14940 KB Output is correct
10 Correct 4 ms 14940 KB Output is correct
11 Correct 5 ms 14940 KB Output is correct
12 Correct 4 ms 14936 KB Output is correct
13 Correct 6 ms 15452 KB Output is correct
14 Correct 4 ms 14940 KB Output is correct
15 Correct 4 ms 14940 KB Output is correct
16 Correct 4 ms 14936 KB Output is correct
17 Correct 4 ms 14940 KB Output is correct
18 Correct 4 ms 14940 KB Output is correct
19 Correct 5 ms 14936 KB Output is correct
20 Correct 4 ms 14940 KB Output is correct
21 Correct 5 ms 14992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 14940 KB Output is correct
2 Correct 5 ms 15188 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
4 Correct 4 ms 14940 KB Output is correct
5 Correct 4 ms 14940 KB Output is correct
6 Correct 4 ms 14940 KB Output is correct
7 Correct 4 ms 14936 KB Output is correct
8 Correct 4 ms 14940 KB Output is correct
9 Correct 4 ms 14940 KB Output is correct
10 Correct 4 ms 14940 KB Output is correct
11 Correct 5 ms 14940 KB Output is correct
12 Correct 4 ms 14936 KB Output is correct
13 Correct 6 ms 15452 KB Output is correct
14 Correct 4 ms 14940 KB Output is correct
15 Correct 4 ms 14940 KB Output is correct
16 Correct 4 ms 14936 KB Output is correct
17 Correct 4 ms 14940 KB Output is correct
18 Correct 4 ms 14940 KB Output is correct
19 Correct 5 ms 14936 KB Output is correct
20 Correct 4 ms 14940 KB Output is correct
21 Correct 5 ms 14992 KB Output is correct
22 Correct 5 ms 14940 KB Output is correct
23 Correct 6 ms 14936 KB Output is correct
24 Correct 5 ms 14940 KB Output is correct
25 Correct 6 ms 14936 KB Output is correct
26 Correct 5 ms 14936 KB Output is correct
27 Correct 6 ms 14936 KB Output is correct
28 Correct 5 ms 14940 KB Output is correct
29 Correct 5 ms 15096 KB Output is correct
30 Correct 5 ms 15192 KB Output is correct
31 Correct 6 ms 14940 KB Output is correct
32 Correct 6 ms 14964 KB Output is correct
33 Correct 5 ms 14940 KB Output is correct
34 Correct 6 ms 14936 KB Output is correct
35 Correct 7 ms 14936 KB Output is correct
36 Correct 6 ms 14936 KB Output is correct
37 Correct 5 ms 14936 KB Output is correct
38 Correct 5 ms 14940 KB Output is correct
39 Correct 6 ms 14940 KB Output is correct
40 Correct 6 ms 14940 KB Output is correct
41 Correct 7 ms 14996 KB Output is correct
42 Correct 6 ms 14940 KB Output is correct
43 Correct 6 ms 14940 KB Output is correct
44 Correct 5 ms 14968 KB Output is correct
45 Correct 5 ms 14940 KB Output is correct
46 Correct 5 ms 14940 KB Output is correct
47 Correct 5 ms 14940 KB Output is correct
48 Correct 5 ms 14940 KB Output is correct
49 Correct 5 ms 14940 KB Output is correct
50 Correct 6 ms 14940 KB Output is correct
51 Correct 5 ms 14940 KB Output is correct
52 Correct 6 ms 14940 KB Output is correct
53 Correct 6 ms 14940 KB Output is correct
54 Correct 7 ms 14940 KB Output is correct
55 Correct 5 ms 15068 KB Output is correct
56 Correct 5 ms 14940 KB Output is correct
57 Correct 5 ms 15196 KB Output is correct
58 Correct 5 ms 14964 KB Output is correct
59 Correct 6 ms 14940 KB Output is correct
60 Correct 6 ms 14940 KB Output is correct
61 Correct 5 ms 15072 KB Output is correct
62 Correct 5 ms 15192 KB Output is correct
63 Correct 5 ms 14940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 14940 KB Output is correct
2 Correct 5 ms 15188 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
4 Correct 4 ms 14940 KB Output is correct
5 Correct 4 ms 14940 KB Output is correct
6 Correct 4 ms 14940 KB Output is correct
7 Correct 4 ms 14936 KB Output is correct
8 Correct 4 ms 14940 KB Output is correct
9 Correct 4 ms 14940 KB Output is correct
10 Correct 4 ms 14940 KB Output is correct
11 Correct 5 ms 14940 KB Output is correct
12 Correct 4 ms 14936 KB Output is correct
13 Correct 6 ms 15452 KB Output is correct
14 Correct 4 ms 14940 KB Output is correct
15 Correct 4 ms 14940 KB Output is correct
16 Correct 4 ms 14936 KB Output is correct
17 Correct 4 ms 14940 KB Output is correct
18 Correct 4 ms 14940 KB Output is correct
19 Correct 5 ms 14936 KB Output is correct
20 Correct 4 ms 14940 KB Output is correct
21 Correct 5 ms 14992 KB Output is correct
22 Correct 5 ms 14940 KB Output is correct
23 Correct 6 ms 14936 KB Output is correct
24 Correct 5 ms 14940 KB Output is correct
25 Correct 6 ms 14936 KB Output is correct
26 Correct 5 ms 14936 KB Output is correct
27 Correct 6 ms 14936 KB Output is correct
28 Correct 5 ms 14940 KB Output is correct
29 Correct 5 ms 15096 KB Output is correct
30 Correct 5 ms 15192 KB Output is correct
31 Correct 6 ms 14940 KB Output is correct
32 Correct 6 ms 14964 KB Output is correct
33 Correct 5 ms 14940 KB Output is correct
34 Correct 6 ms 14936 KB Output is correct
35 Correct 7 ms 14936 KB Output is correct
36 Correct 6 ms 14936 KB Output is correct
37 Correct 5 ms 14936 KB Output is correct
38 Correct 5 ms 14940 KB Output is correct
39 Correct 6 ms 14940 KB Output is correct
40 Correct 6 ms 14940 KB Output is correct
41 Correct 7 ms 14996 KB Output is correct
42 Correct 6 ms 14940 KB Output is correct
43 Correct 6 ms 14940 KB Output is correct
44 Correct 5 ms 14968 KB Output is correct
45 Correct 5 ms 14940 KB Output is correct
46 Correct 5 ms 14940 KB Output is correct
47 Correct 5 ms 14940 KB Output is correct
48 Correct 5 ms 14940 KB Output is correct
49 Correct 5 ms 14940 KB Output is correct
50 Correct 6 ms 14940 KB Output is correct
51 Correct 5 ms 14940 KB Output is correct
52 Correct 6 ms 14940 KB Output is correct
53 Correct 6 ms 14940 KB Output is correct
54 Correct 7 ms 14940 KB Output is correct
55 Correct 5 ms 15068 KB Output is correct
56 Correct 5 ms 14940 KB Output is correct
57 Correct 5 ms 15196 KB Output is correct
58 Correct 5 ms 14964 KB Output is correct
59 Correct 6 ms 14940 KB Output is correct
60 Correct 6 ms 14940 KB Output is correct
61 Correct 5 ms 15072 KB Output is correct
62 Correct 5 ms 15192 KB Output is correct
63 Correct 5 ms 14940 KB Output is correct
64 Correct 206 ms 25072 KB Output is correct
65 Correct 163 ms 24916 KB Output is correct
66 Correct 200 ms 24916 KB Output is correct
67 Correct 166 ms 24912 KB Output is correct
68 Correct 166 ms 24916 KB Output is correct
69 Correct 172 ms 24912 KB Output is correct
70 Correct 164 ms 25028 KB Output is correct
71 Correct 214 ms 25168 KB Output is correct
72 Correct 151 ms 24912 KB Output is correct
73 Correct 208 ms 40056 KB Output is correct
74 Correct 226 ms 40276 KB Output is correct
75 Correct 153 ms 24912 KB Output is correct
76 Correct 154 ms 24924 KB Output is correct
77 Correct 175 ms 25168 KB Output is correct
78 Correct 158 ms 24916 KB Output is correct
79 Correct 198 ms 24972 KB Output is correct
80 Correct 159 ms 24796 KB Output is correct
81 Correct 175 ms 25252 KB Output is correct
82 Correct 156 ms 25180 KB Output is correct
83 Correct 176 ms 31060 KB Output is correct
84 Correct 181 ms 33648 KB Output is correct
85 Correct 184 ms 33172 KB Output is correct
86 Correct 197 ms 26524 KB Output is correct
87 Correct 167 ms 26000 KB Output is correct
88 Correct 156 ms 26196 KB Output is correct
89 Correct 181 ms 26452 KB Output is correct
90 Correct 171 ms 26452 KB Output is correct
91 Correct 266 ms 26280 KB Output is correct
92 Correct 182 ms 26660 KB Output is correct
93 Correct 193 ms 29788 KB Output is correct
94 Correct 151 ms 31688 KB Output is correct
95 Correct 195 ms 30188 KB Output is correct
96 Correct 174 ms 27944 KB Output is correct
97 Correct 158 ms 26196 KB Output is correct
98 Correct 178 ms 25568 KB Output is correct
99 Correct 167 ms 25412 KB Output is correct
100 Correct 164 ms 29008 KB Output is correct
101 Correct 201 ms 26900 KB Output is correct
102 Correct 163 ms 25680 KB Output is correct
103 Correct 155 ms 25600 KB Output is correct
104 Correct 133 ms 25824 KB Output is correct
105 Correct 217 ms 36180 KB Output is correct
106 Correct 127 ms 25604 KB Output is correct
107 Correct 127 ms 25448 KB Output is correct
108 Correct 196 ms 41044 KB Output is correct
109 Correct 149 ms 25800 KB Output is correct
110 Correct 232 ms 41372 KB Output is correct
111 Correct 188 ms 24824 KB Output is correct