Submission #623027

# Submission time Handle Problem Language Result Execution time Memory
623027 2022-08-05T05:39:04 Z S2speed Power Plant (JOI20_power) C++17
100 / 100
160 ms 29832 KB
#include<bits/stdc++.h>

using namespace std;

#pragma GCC optimize ("Ofast")

typedef long long ll;

const ll maxn = 2e5 + 17;

vector<ll> adj[maxn];
string s;
ll dp[maxn] , ans = 0;

void DFS(ll r , ll par){
	ll h = 0 , m = -1;
	for(auto i : adj[r]){
		if(i == par) continue;
		DFS(i , r);
		h += dp[i];
		m = max(m , dp[i]);
	}
	ans = max(ans , m + (s[r] == '1'));
	if(h == 0){
		dp[r] = (s[r] == '1');
	} else {
		dp[r] = max((ll)(s[r] == '1') , h - (s[r] == '1'));
	}
	ans = max(ans , dp[r]);
	return;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	ll n;
	cin>>n;
	for(ll i = 1 ; i < n ; i++){
		ll v , u;
		cin>>v>>u; v--; u--;
		adj[v].push_back(u); adj[u].push_back(v);
	}
	cin>>s;
	DFS(0 , -1);
	cout<<ans<<'\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 5024 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 5028 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 5032 KB Output is correct
9 Correct 3 ms 5024 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 5028 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 5028 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 5028 KB Output is correct
20 Correct 4 ms 5076 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 5024 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 5028 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 5032 KB Output is correct
9 Correct 3 ms 5024 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 5028 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 5028 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 5028 KB Output is correct
20 Correct 4 ms 5076 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 4 ms 5040 KB Output is correct
23 Correct 4 ms 5076 KB Output is correct
24 Correct 4 ms 5040 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 5088 KB Output is correct
28 Correct 3 ms 5084 KB Output is correct
29 Correct 4 ms 5204 KB Output is correct
30 Correct 3 ms 5088 KB Output is correct
31 Correct 4 ms 5076 KB Output is correct
32 Correct 3 ms 5076 KB Output is correct
33 Correct 4 ms 5076 KB Output is correct
34 Correct 3 ms 5076 KB Output is correct
35 Correct 3 ms 5076 KB Output is correct
36 Correct 3 ms 5068 KB Output is correct
37 Correct 4 ms 5076 KB Output is correct
38 Correct 3 ms 5076 KB Output is correct
39 Correct 3 ms 5076 KB Output is correct
40 Correct 3 ms 5076 KB Output is correct
41 Correct 3 ms 5076 KB Output is correct
42 Correct 4 ms 5160 KB Output is correct
43 Correct 3 ms 5076 KB Output is correct
44 Correct 3 ms 5076 KB Output is correct
45 Correct 5 ms 5076 KB Output is correct
46 Correct 4 ms 5120 KB Output is correct
47 Correct 4 ms 5076 KB Output is correct
48 Correct 3 ms 5204 KB Output is correct
49 Correct 5 ms 5084 KB Output is correct
50 Correct 3 ms 5076 KB Output is correct
51 Correct 3 ms 5076 KB Output is correct
52 Correct 3 ms 5076 KB Output is correct
53 Correct 3 ms 5076 KB Output is correct
54 Correct 3 ms 5076 KB Output is correct
55 Correct 3 ms 5084 KB Output is correct
56 Correct 3 ms 5076 KB Output is correct
57 Correct 3 ms 5164 KB Output is correct
58 Correct 3 ms 5076 KB Output is correct
59 Correct 3 ms 5076 KB Output is correct
60 Correct 3 ms 5088 KB Output is correct
61 Correct 3 ms 5032 KB Output is correct
62 Correct 4 ms 5204 KB Output is correct
63 Correct 3 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 5024 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 5028 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 5032 KB Output is correct
9 Correct 3 ms 5024 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 5028 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 5028 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 5028 KB Output is correct
20 Correct 4 ms 5076 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 4 ms 5040 KB Output is correct
23 Correct 4 ms 5076 KB Output is correct
24 Correct 4 ms 5040 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 5088 KB Output is correct
28 Correct 3 ms 5084 KB Output is correct
29 Correct 4 ms 5204 KB Output is correct
30 Correct 3 ms 5088 KB Output is correct
31 Correct 4 ms 5076 KB Output is correct
32 Correct 3 ms 5076 KB Output is correct
33 Correct 4 ms 5076 KB Output is correct
34 Correct 3 ms 5076 KB Output is correct
35 Correct 3 ms 5076 KB Output is correct
36 Correct 3 ms 5068 KB Output is correct
37 Correct 4 ms 5076 KB Output is correct
38 Correct 3 ms 5076 KB Output is correct
39 Correct 3 ms 5076 KB Output is correct
40 Correct 3 ms 5076 KB Output is correct
41 Correct 3 ms 5076 KB Output is correct
42 Correct 4 ms 5160 KB Output is correct
43 Correct 3 ms 5076 KB Output is correct
44 Correct 3 ms 5076 KB Output is correct
45 Correct 5 ms 5076 KB Output is correct
46 Correct 4 ms 5120 KB Output is correct
47 Correct 4 ms 5076 KB Output is correct
48 Correct 3 ms 5204 KB Output is correct
49 Correct 5 ms 5084 KB Output is correct
50 Correct 3 ms 5076 KB Output is correct
51 Correct 3 ms 5076 KB Output is correct
52 Correct 3 ms 5076 KB Output is correct
53 Correct 3 ms 5076 KB Output is correct
54 Correct 3 ms 5076 KB Output is correct
55 Correct 3 ms 5084 KB Output is correct
56 Correct 3 ms 5076 KB Output is correct
57 Correct 3 ms 5164 KB Output is correct
58 Correct 3 ms 5076 KB Output is correct
59 Correct 3 ms 5076 KB Output is correct
60 Correct 3 ms 5088 KB Output is correct
61 Correct 3 ms 5032 KB Output is correct
62 Correct 4 ms 5204 KB Output is correct
63 Correct 3 ms 5076 KB Output is correct
64 Correct 156 ms 16880 KB Output is correct
65 Correct 118 ms 16908 KB Output is correct
66 Correct 143 ms 16888 KB Output is correct
67 Correct 146 ms 16916 KB Output is correct
68 Correct 116 ms 16976 KB Output is correct
69 Correct 111 ms 16884 KB Output is correct
70 Correct 117 ms 16896 KB Output is correct
71 Correct 160 ms 17060 KB Output is correct
72 Correct 116 ms 16900 KB Output is correct
73 Correct 135 ms 28492 KB Output is correct
74 Correct 155 ms 28444 KB Output is correct
75 Correct 135 ms 18216 KB Output is correct
76 Correct 124 ms 18132 KB Output is correct
77 Correct 144 ms 16924 KB Output is correct
78 Correct 116 ms 16924 KB Output is correct
79 Correct 130 ms 16876 KB Output is correct
80 Correct 144 ms 16908 KB Output is correct
81 Correct 97 ms 16940 KB Output is correct
82 Correct 102 ms 16980 KB Output is correct
83 Correct 129 ms 22056 KB Output is correct
84 Correct 143 ms 24088 KB Output is correct
85 Correct 123 ms 23920 KB Output is correct
86 Correct 116 ms 18252 KB Output is correct
87 Correct 114 ms 17668 KB Output is correct
88 Correct 110 ms 17768 KB Output is correct
89 Correct 108 ms 17860 KB Output is correct
90 Correct 113 ms 17620 KB Output is correct
91 Correct 108 ms 17856 KB Output is correct
92 Correct 131 ms 18132 KB Output is correct
93 Correct 139 ms 20392 KB Output is correct
94 Correct 104 ms 21976 KB Output is correct
95 Correct 102 ms 20840 KB Output is correct
96 Correct 112 ms 18920 KB Output is correct
97 Correct 147 ms 17492 KB Output is correct
98 Correct 99 ms 17084 KB Output is correct
99 Correct 108 ms 17024 KB Output is correct
100 Correct 102 ms 19964 KB Output is correct
101 Correct 154 ms 17844 KB Output is correct
102 Correct 104 ms 17200 KB Output is correct
103 Correct 114 ms 17220 KB Output is correct
104 Correct 62 ms 17596 KB Output is correct
105 Correct 157 ms 25404 KB Output is correct
106 Correct 62 ms 17520 KB Output is correct
107 Correct 64 ms 17440 KB Output is correct
108 Correct 131 ms 29360 KB Output is correct
109 Correct 71 ms 17536 KB Output is correct
110 Correct 138 ms 29832 KB Output is correct
111 Correct 102 ms 16816 KB Output is correct