Submission #943611

# Submission time Handle Problem Language Result Execution time Memory
943611 2024-03-11T16:24:48 Z aqxa Power Plant (JOI20_power) C++17
100 / 100
149 ms 34564 KB
#include <bits/stdc++.h>
using namespace std; 

using ll = long long; 

const int N = 2e5 + 10; 

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

	int n; 
	cin >> n; 
	vector<vector<int>> g(n); 
	for (int i = 0; i < n - 1; ++i) {
		int x, y; 
		cin >> x >> y; 
		x--; y--; 
		g[x].push_back(y); 
		g[y].push_back(x); 
	}
	string s; 
	cin >> s; 

	int ans = 0; 
	vector<int> dp(n, 0); 
	function<void(int, int)> dfs = [&] (int x, int p) {
		int c = 0, mx = 0; 
		for (auto y: g[x]) {
			if (y != p) {
				dfs(y, x); 
				c += dp[y]; 
				mx = max(mx, dp[y]); 
			}
		}
		
		if (s[x] == '1') {
			ans = max(ans, 1 + mx); 
			ans = max(ans, c - 1); 
			dp[x] = max(1, max(c - 1, mx - 1)); 
		} else {
			dp[x] = max(c, 0); 
			ans = max(ans, dp[x]); 
		}
	}; 
	dfs(0, -1); 

	// for (int i = 0; i < n; ++i) cout << dp[i] << '\n';
	
	cout << ans << "\n";

}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 464 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 472 KB Output is correct
27 Correct 1 ms 600 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 1 ms 464 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 1 ms 464 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 600 KB Output is correct
46 Correct 1 ms 600 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 1 ms 584 KB Output is correct
49 Correct 2 ms 604 KB Output is correct
50 Correct 1 ms 468 KB Output is correct
51 Correct 1 ms 600 KB Output is correct
52 Correct 1 ms 604 KB Output is correct
53 Correct 2 ms 604 KB Output is correct
54 Correct 1 ms 604 KB Output is correct
55 Correct 1 ms 604 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 1 ms 604 KB Output is correct
58 Correct 1 ms 596 KB Output is correct
59 Correct 1 ms 600 KB Output is correct
60 Correct 1 ms 600 KB Output is correct
61 Correct 1 ms 604 KB Output is correct
62 Correct 1 ms 604 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 464 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 472 KB Output is correct
27 Correct 1 ms 600 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 1 ms 464 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 1 ms 464 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 600 KB Output is correct
46 Correct 1 ms 600 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 1 ms 584 KB Output is correct
49 Correct 2 ms 604 KB Output is correct
50 Correct 1 ms 468 KB Output is correct
51 Correct 1 ms 600 KB Output is correct
52 Correct 1 ms 604 KB Output is correct
53 Correct 2 ms 604 KB Output is correct
54 Correct 1 ms 604 KB Output is correct
55 Correct 1 ms 604 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 1 ms 604 KB Output is correct
58 Correct 1 ms 596 KB Output is correct
59 Correct 1 ms 600 KB Output is correct
60 Correct 1 ms 600 KB Output is correct
61 Correct 1 ms 604 KB Output is correct
62 Correct 1 ms 604 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 63 ms 15272 KB Output is correct
65 Correct 89 ms 15240 KB Output is correct
66 Correct 108 ms 15220 KB Output is correct
67 Correct 137 ms 15188 KB Output is correct
68 Correct 63 ms 15232 KB Output is correct
69 Correct 122 ms 15352 KB Output is correct
70 Correct 95 ms 15284 KB Output is correct
71 Correct 86 ms 15360 KB Output is correct
72 Correct 114 ms 15244 KB Output is correct
73 Correct 91 ms 32916 KB Output is correct
74 Correct 135 ms 32940 KB Output is correct
75 Correct 66 ms 15092 KB Output is correct
76 Correct 68 ms 15168 KB Output is correct
77 Correct 85 ms 15012 KB Output is correct
78 Correct 85 ms 15244 KB Output is correct
79 Correct 93 ms 15120 KB Output is correct
80 Correct 66 ms 14988 KB Output is correct
81 Correct 110 ms 15564 KB Output is correct
82 Correct 106 ms 15444 KB Output is correct
83 Correct 138 ms 22288 KB Output is correct
84 Correct 86 ms 25508 KB Output is correct
85 Correct 104 ms 24928 KB Output is correct
86 Correct 149 ms 17080 KB Output is correct
87 Correct 81 ms 16268 KB Output is correct
88 Correct 67 ms 16588 KB Output is correct
89 Correct 91 ms 16716 KB Output is correct
90 Correct 103 ms 16368 KB Output is correct
91 Correct 93 ms 16752 KB Output is correct
92 Correct 131 ms 17276 KB Output is correct
93 Correct 82 ms 20736 KB Output is correct
94 Correct 73 ms 23244 KB Output is correct
95 Correct 108 ms 21140 KB Output is correct
96 Correct 68 ms 18684 KB Output is correct
97 Correct 103 ms 16448 KB Output is correct
98 Correct 82 ms 15808 KB Output is correct
99 Correct 75 ms 15704 KB Output is correct
100 Correct 84 ms 20012 KB Output is correct
101 Correct 78 ms 17340 KB Output is correct
102 Correct 78 ms 16228 KB Output is correct
103 Correct 77 ms 15796 KB Output is correct
104 Correct 43 ms 16080 KB Output is correct
105 Correct 103 ms 28568 KB Output is correct
106 Correct 58 ms 16072 KB Output is correct
107 Correct 43 ms 15940 KB Output is correct
108 Correct 96 ms 34060 KB Output is correct
109 Correct 44 ms 16072 KB Output is correct
110 Correct 93 ms 34564 KB Output is correct
111 Correct 68 ms 15232 KB Output is correct