Submission #683904

# Submission time Handle Problem Language Result Execution time Memory
683904 2023-01-19T15:31:23 Z alvingogo Power Plant (JOI20_power) C++14
100 / 100
195 ms 24940 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define AquA cin.tie(0);ios_base::sync_with_stdio(0);
#define fs first
#define sc second
#define p_q priority_queue
using namespace std;

struct no{
	vector<int> ch;
	int t;
	int dp=0;	
};
vector<no> v;
int ans=1;
void dfs(int r,int f){
	for(auto h:v[r].ch){
		if(h!=f){
			dfs(h,r);
			v[r].dp+=v[h].dp;
		}
	}
	if(v[r].t==1){
		v[r].dp=max(v[r].dp-1,1);
	}
}
void dfs2(int r,int f,int x){
	v[r].dp+=x;
	ans=max(ans,v[r].dp);
	for(auto h:v[r].ch){
		if(h!=f){
			dfs2(h,r,max(v[r].t,v[r].dp-v[h].dp));
		}
	}
}
int main(){
    AquA;
	int n;
	cin >> n;
	v.resize(n);
	for(int i=1;i<n;i++){
		int a,b;
		cin >> a >> b;
		a--;
		b--;
		v[a].ch.push_back(b);
		v[b].ch.push_back(a);
	}
	string s;
	cin >> s;
	for(int i=0;i<n;i++){
		v[i].t=s[i]-'0';
	}
	dfs(0,0);
	dfs2(0,0,0);
	cout << ans << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 456 KB Output is correct
25 Correct 1 ms 444 KB Output is correct
26 Correct 2 ms 448 KB Output is correct
27 Correct 1 ms 456 KB Output is correct
28 Correct 1 ms 460 KB Output is correct
29 Correct 1 ms 456 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 464 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 1 ms 464 KB Output is correct
38 Correct 1 ms 448 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 1 ms 456 KB Output is correct
44 Correct 1 ms 468 KB Output is correct
45 Correct 1 ms 468 KB Output is correct
46 Correct 1 ms 440 KB Output is correct
47 Correct 1 ms 468 KB Output is correct
48 Correct 1 ms 468 KB Output is correct
49 Correct 1 ms 468 KB Output is correct
50 Correct 1 ms 468 KB Output is correct
51 Correct 1 ms 468 KB Output is correct
52 Correct 1 ms 468 KB Output is correct
53 Correct 1 ms 468 KB Output is correct
54 Correct 1 ms 468 KB Output is correct
55 Correct 1 ms 468 KB Output is correct
56 Correct 1 ms 464 KB Output is correct
57 Correct 1 ms 456 KB Output is correct
58 Correct 1 ms 468 KB Output is correct
59 Correct 1 ms 436 KB Output is correct
60 Correct 1 ms 460 KB Output is correct
61 Correct 1 ms 468 KB Output is correct
62 Correct 1 ms 468 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 456 KB Output is correct
25 Correct 1 ms 444 KB Output is correct
26 Correct 2 ms 448 KB Output is correct
27 Correct 1 ms 456 KB Output is correct
28 Correct 1 ms 460 KB Output is correct
29 Correct 1 ms 456 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 464 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 1 ms 464 KB Output is correct
38 Correct 1 ms 448 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 1 ms 456 KB Output is correct
44 Correct 1 ms 468 KB Output is correct
45 Correct 1 ms 468 KB Output is correct
46 Correct 1 ms 440 KB Output is correct
47 Correct 1 ms 468 KB Output is correct
48 Correct 1 ms 468 KB Output is correct
49 Correct 1 ms 468 KB Output is correct
50 Correct 1 ms 468 KB Output is correct
51 Correct 1 ms 468 KB Output is correct
52 Correct 1 ms 468 KB Output is correct
53 Correct 1 ms 468 KB Output is correct
54 Correct 1 ms 468 KB Output is correct
55 Correct 1 ms 468 KB Output is correct
56 Correct 1 ms 464 KB Output is correct
57 Correct 1 ms 456 KB Output is correct
58 Correct 1 ms 468 KB Output is correct
59 Correct 1 ms 436 KB Output is correct
60 Correct 1 ms 460 KB Output is correct
61 Correct 1 ms 468 KB Output is correct
62 Correct 1 ms 468 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 142 ms 14112 KB Output is correct
65 Correct 167 ms 14120 KB Output is correct
66 Correct 144 ms 14116 KB Output is correct
67 Correct 141 ms 14144 KB Output is correct
68 Correct 155 ms 14140 KB Output is correct
69 Correct 137 ms 14124 KB Output is correct
70 Correct 146 ms 14056 KB Output is correct
71 Correct 155 ms 14132 KB Output is correct
72 Correct 136 ms 14140 KB Output is correct
73 Correct 172 ms 24016 KB Output is correct
74 Correct 195 ms 24036 KB Output is correct
75 Correct 138 ms 14052 KB Output is correct
76 Correct 180 ms 14040 KB Output is correct
77 Correct 159 ms 13996 KB Output is correct
78 Correct 158 ms 14060 KB Output is correct
79 Correct 178 ms 14008 KB Output is correct
80 Correct 136 ms 13944 KB Output is correct
81 Correct 120 ms 14364 KB Output is correct
82 Correct 142 ms 14176 KB Output is correct
83 Correct 173 ms 18040 KB Output is correct
84 Correct 183 ms 19768 KB Output is correct
85 Correct 161 ms 19524 KB Output is correct
86 Correct 159 ms 15056 KB Output is correct
87 Correct 181 ms 14612 KB Output is correct
88 Correct 136 ms 15048 KB Output is correct
89 Correct 140 ms 15036 KB Output is correct
90 Correct 164 ms 14960 KB Output is correct
91 Correct 126 ms 15156 KB Output is correct
92 Correct 153 ms 15356 KB Output is correct
93 Correct 164 ms 17224 KB Output is correct
94 Correct 143 ms 18664 KB Output is correct
95 Correct 120 ms 17536 KB Output is correct
96 Correct 130 ms 16260 KB Output is correct
97 Correct 148 ms 14932 KB Output is correct
98 Correct 129 ms 14488 KB Output is correct
99 Correct 143 ms 14452 KB Output is correct
100 Correct 170 ms 16904 KB Output is correct
101 Correct 138 ms 15224 KB Output is correct
102 Correct 141 ms 14772 KB Output is correct
103 Correct 169 ms 14500 KB Output is correct
104 Correct 77 ms 14732 KB Output is correct
105 Correct 166 ms 21432 KB Output is correct
106 Correct 70 ms 14844 KB Output is correct
107 Correct 110 ms 14872 KB Output is correct
108 Correct 195 ms 24684 KB Output is correct
109 Correct 105 ms 14696 KB Output is correct
110 Correct 179 ms 24940 KB Output is correct
111 Correct 125 ms 14112 KB Output is correct