# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
550550 | 2022-04-18T13:15:21 Z | krit3379 | Power Plant (JOI20_power) | C++17 | 196 ms | 29516 KB |
#include<bits/stdc++.h> using namespace std; #define N 200005 int dp[N],p[N],ans; char s[N]; vector<int> g[N]; void dfs(int s,int f){ int ma=0; for(auto x:g[s]){ if(x==f)continue; dfs(x,s); dp[s]+=dp[x]; ma=max(ma,dp[x]); } dp[s]-=p[s]; dp[s]=max(dp[s],p[s]); ans=max({ans,ma+p[s],dp[s]}); } int main(){ int n,i,a,b; scanf("%d",&n); for(i=1;i<n;i++){ scanf("%d %d",&a,&b); g[a].push_back(b); g[b].push_back(a); } scanf(" %s",s+1); for(i=1;i<=n;i++)p[i]=s[i]-'0'; dfs(1,0); printf("%d",ans); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4948 KB | Output is correct |
2 | Correct | 2 ms | 4948 KB | Output is correct |
3 | Correct | 2 ms | 5008 KB | Output is correct |
4 | Correct | 3 ms | 4948 KB | Output is correct |
5 | Correct | 3 ms | 5012 KB | Output is correct |
6 | Correct | 3 ms | 5016 KB | Output is correct |
7 | Correct | 3 ms | 4948 KB | Output is correct |
8 | Correct | 4 ms | 4948 KB | Output is correct |
9 | Correct | 3 ms | 5012 KB | Output is correct |
10 | Correct | 4 ms | 4948 KB | Output is correct |
11 | Correct | 4 ms | 4924 KB | Output is correct |
12 | Correct | 3 ms | 4948 KB | Output is correct |
13 | Correct | 3 ms | 4948 KB | Output is correct |
14 | Correct | 4 ms | 4984 KB | Output is correct |
15 | Correct | 2 ms | 4948 KB | Output is correct |
16 | Correct | 3 ms | 4948 KB | Output is correct |
17 | Correct | 3 ms | 4948 KB | Output is correct |
18 | Correct | 3 ms | 4948 KB | Output is correct |
19 | Correct | 3 ms | 4948 KB | Output is correct |
20 | Correct | 3 ms | 5012 KB | Output is correct |
21 | Correct | 4 ms | 4948 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4948 KB | Output is correct |
2 | Correct | 2 ms | 4948 KB | Output is correct |
3 | Correct | 2 ms | 5008 KB | Output is correct |
4 | Correct | 3 ms | 4948 KB | Output is correct |
5 | Correct | 3 ms | 5012 KB | Output is correct |
6 | Correct | 3 ms | 5016 KB | Output is correct |
7 | Correct | 3 ms | 4948 KB | Output is correct |
8 | Correct | 4 ms | 4948 KB | Output is correct |
9 | Correct | 3 ms | 5012 KB | Output is correct |
10 | Correct | 4 ms | 4948 KB | Output is correct |
11 | Correct | 4 ms | 4924 KB | Output is correct |
12 | Correct | 3 ms | 4948 KB | Output is correct |
13 | Correct | 3 ms | 4948 KB | Output is correct |
14 | Correct | 4 ms | 4984 KB | Output is correct |
15 | Correct | 2 ms | 4948 KB | Output is correct |
16 | Correct | 3 ms | 4948 KB | Output is correct |
17 | Correct | 3 ms | 4948 KB | Output is correct |
18 | Correct | 3 ms | 4948 KB | Output is correct |
19 | Correct | 3 ms | 4948 KB | Output is correct |
20 | Correct | 3 ms | 5012 KB | Output is correct |
21 | Correct | 4 ms | 4948 KB | Output is correct |
22 | Correct | 4 ms | 5032 KB | Output is correct |
23 | Correct | 4 ms | 5076 KB | Output is correct |
24 | Correct | 4 ms | 5028 KB | Output is correct |
25 | Correct | 4 ms | 5076 KB | Output is correct |
26 | Correct | 4 ms | 5076 KB | Output is correct |
27 | Correct | 4 ms | 5036 KB | Output is correct |
28 | Correct | 4 ms | 5028 KB | Output is correct |
29 | Correct | 3 ms | 5204 KB | Output is correct |
30 | Correct | 4 ms | 5160 KB | Output is correct |
31 | Correct | 3 ms | 5076 KB | Output is correct |
32 | Correct | 3 ms | 5024 KB | Output is correct |
33 | Correct | 3 ms | 5076 KB | Output is correct |
34 | Correct | 4 ms | 5096 KB | Output is correct |
35 | Correct | 4 ms | 5076 KB | Output is correct |
36 | Correct | 4 ms | 5076 KB | Output is correct |
37 | Correct | 4 ms | 5012 KB | Output is correct |
38 | Correct | 4 ms | 5028 KB | Output is correct |
39 | Correct | 4 ms | 5084 KB | Output is correct |
40 | Correct | 5 ms | 5076 KB | Output is correct |
41 | Correct | 5 ms | 5076 KB | Output is correct |
42 | Correct | 4 ms | 5032 KB | Output is correct |
43 | Correct | 3 ms | 5076 KB | Output is correct |
44 | Correct | 3 ms | 5040 KB | Output is correct |
45 | Correct | 3 ms | 5076 KB | Output is correct |
46 | Correct | 3 ms | 5016 KB | Output is correct |
47 | Correct | 3 ms | 5032 KB | Output is correct |
48 | Correct | 3 ms | 5076 KB | Output is correct |
49 | Correct | 4 ms | 5152 KB | Output is correct |
50 | Correct | 5 ms | 5156 KB | Output is correct |
51 | Correct | 4 ms | 5148 KB | Output is correct |
52 | Correct | 4 ms | 5076 KB | Output is correct |
53 | Correct | 5 ms | 5076 KB | Output is correct |
54 | Correct | 9 ms | 5088 KB | Output is correct |
55 | Correct | 5 ms | 5076 KB | Output is correct |
56 | Correct | 4 ms | 5088 KB | Output is correct |
57 | Correct | 5 ms | 5204 KB | Output is correct |
58 | Correct | 4 ms | 5076 KB | Output is correct |
59 | Correct | 3 ms | 5076 KB | Output is correct |
60 | Correct | 4 ms | 5076 KB | Output is correct |
61 | Correct | 3 ms | 5076 KB | Output is correct |
62 | Correct | 4 ms | 5204 KB | Output is correct |
63 | Correct | 3 ms | 5076 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4948 KB | Output is correct |
2 | Correct | 2 ms | 4948 KB | Output is correct |
3 | Correct | 2 ms | 5008 KB | Output is correct |
4 | Correct | 3 ms | 4948 KB | Output is correct |
5 | Correct | 3 ms | 5012 KB | Output is correct |
6 | Correct | 3 ms | 5016 KB | Output is correct |
7 | Correct | 3 ms | 4948 KB | Output is correct |
8 | Correct | 4 ms | 4948 KB | Output is correct |
9 | Correct | 3 ms | 5012 KB | Output is correct |
10 | Correct | 4 ms | 4948 KB | Output is correct |
11 | Correct | 4 ms | 4924 KB | Output is correct |
12 | Correct | 3 ms | 4948 KB | Output is correct |
13 | Correct | 3 ms | 4948 KB | Output is correct |
14 | Correct | 4 ms | 4984 KB | Output is correct |
15 | Correct | 2 ms | 4948 KB | Output is correct |
16 | Correct | 3 ms | 4948 KB | Output is correct |
17 | Correct | 3 ms | 4948 KB | Output is correct |
18 | Correct | 3 ms | 4948 KB | Output is correct |
19 | Correct | 3 ms | 4948 KB | Output is correct |
20 | Correct | 3 ms | 5012 KB | Output is correct |
21 | Correct | 4 ms | 4948 KB | Output is correct |
22 | Correct | 4 ms | 5032 KB | Output is correct |
23 | Correct | 4 ms | 5076 KB | Output is correct |
24 | Correct | 4 ms | 5028 KB | Output is correct |
25 | Correct | 4 ms | 5076 KB | Output is correct |
26 | Correct | 4 ms | 5076 KB | Output is correct |
27 | Correct | 4 ms | 5036 KB | Output is correct |
28 | Correct | 4 ms | 5028 KB | Output is correct |
29 | Correct | 3 ms | 5204 KB | Output is correct |
30 | Correct | 4 ms | 5160 KB | Output is correct |
31 | Correct | 3 ms | 5076 KB | Output is correct |
32 | Correct | 3 ms | 5024 KB | Output is correct |
33 | Correct | 3 ms | 5076 KB | Output is correct |
34 | Correct | 4 ms | 5096 KB | Output is correct |
35 | Correct | 4 ms | 5076 KB | Output is correct |
36 | Correct | 4 ms | 5076 KB | Output is correct |
37 | Correct | 4 ms | 5012 KB | Output is correct |
38 | Correct | 4 ms | 5028 KB | Output is correct |
39 | Correct | 4 ms | 5084 KB | Output is correct |
40 | Correct | 5 ms | 5076 KB | Output is correct |
41 | Correct | 5 ms | 5076 KB | Output is correct |
42 | Correct | 4 ms | 5032 KB | Output is correct |
43 | Correct | 3 ms | 5076 KB | Output is correct |
44 | Correct | 3 ms | 5040 KB | Output is correct |
45 | Correct | 3 ms | 5076 KB | Output is correct |
46 | Correct | 3 ms | 5016 KB | Output is correct |
47 | Correct | 3 ms | 5032 KB | Output is correct |
48 | Correct | 3 ms | 5076 KB | Output is correct |
49 | Correct | 4 ms | 5152 KB | Output is correct |
50 | Correct | 5 ms | 5156 KB | Output is correct |
51 | Correct | 4 ms | 5148 KB | Output is correct |
52 | Correct | 4 ms | 5076 KB | Output is correct |
53 | Correct | 5 ms | 5076 KB | Output is correct |
54 | Correct | 9 ms | 5088 KB | Output is correct |
55 | Correct | 5 ms | 5076 KB | Output is correct |
56 | Correct | 4 ms | 5088 KB | Output is correct |
57 | Correct | 5 ms | 5204 KB | Output is correct |
58 | Correct | 4 ms | 5076 KB | Output is correct |
59 | Correct | 3 ms | 5076 KB | Output is correct |
60 | Correct | 4 ms | 5076 KB | Output is correct |
61 | Correct | 3 ms | 5076 KB | Output is correct |
62 | Correct | 4 ms | 5204 KB | Output is correct |
63 | Correct | 3 ms | 5076 KB | Output is correct |
64 | Correct | 160 ms | 15872 KB | Output is correct |
65 | Correct | 156 ms | 15848 KB | Output is correct |
66 | Correct | 131 ms | 15752 KB | Output is correct |
67 | Correct | 155 ms | 15812 KB | Output is correct |
68 | Correct | 173 ms | 15824 KB | Output is correct |
69 | Correct | 141 ms | 15788 KB | Output is correct |
70 | Correct | 149 ms | 15824 KB | Output is correct |
71 | Correct | 152 ms | 15828 KB | Output is correct |
72 | Correct | 132 ms | 15732 KB | Output is correct |
73 | Correct | 168 ms | 28452 KB | Output is correct |
74 | Correct | 147 ms | 28272 KB | Output is correct |
75 | Correct | 177 ms | 15652 KB | Output is correct |
76 | Correct | 146 ms | 15692 KB | Output is correct |
77 | Correct | 134 ms | 15728 KB | Output is correct |
78 | Correct | 161 ms | 15652 KB | Output is correct |
79 | Correct | 162 ms | 15724 KB | Output is correct |
80 | Correct | 162 ms | 15616 KB | Output is correct |
81 | Correct | 113 ms | 16032 KB | Output is correct |
82 | Correct | 137 ms | 15844 KB | Output is correct |
83 | Correct | 172 ms | 20836 KB | Output is correct |
84 | Correct | 162 ms | 23200 KB | Output is correct |
85 | Correct | 154 ms | 22704 KB | Output is correct |
86 | Correct | 149 ms | 17104 KB | Output is correct |
87 | Correct | 148 ms | 16588 KB | Output is correct |
88 | Correct | 123 ms | 17060 KB | Output is correct |
89 | Correct | 159 ms | 17084 KB | Output is correct |
90 | Correct | 140 ms | 16844 KB | Output is correct |
91 | Correct | 134 ms | 17100 KB | Output is correct |
92 | Correct | 143 ms | 17356 KB | Output is correct |
93 | Correct | 160 ms | 19704 KB | Output is correct |
94 | Correct | 122 ms | 21440 KB | Output is correct |
95 | Correct | 127 ms | 20092 KB | Output is correct |
96 | Correct | 123 ms | 18448 KB | Output is correct |
97 | Correct | 153 ms | 16808 KB | Output is correct |
98 | Correct | 112 ms | 16328 KB | Output is correct |
99 | Correct | 126 ms | 16208 KB | Output is correct |
100 | Correct | 130 ms | 19380 KB | Output is correct |
101 | Correct | 180 ms | 17264 KB | Output is correct |
102 | Correct | 127 ms | 16596 KB | Output is correct |
103 | Correct | 127 ms | 16460 KB | Output is correct |
104 | Correct | 99 ms | 16604 KB | Output is correct |
105 | Correct | 196 ms | 25268 KB | Output is correct |
106 | Correct | 81 ms | 16364 KB | Output is correct |
107 | Correct | 83 ms | 16412 KB | Output is correct |
108 | Correct | 167 ms | 29168 KB | Output is correct |
109 | Correct | 109 ms | 16672 KB | Output is correct |
110 | Correct | 149 ms | 29516 KB | Output is correct |
111 | Correct | 125 ms | 15740 KB | Output is correct |