Submission #1050476

# Submission time Handle Problem Language Result Execution time Memory
1050476 2024-08-09T10:02:36 Z n1k Power Plant (JOI20_power) C++17
100 / 100
128 ms 35292 KB
#include <bits/stdc++.h>

#if defined(LOCAL)
#include "debug.cpp"
#else
#define debug(x...) 0
#endif // LOCAL

using namespace std;

using ll = long long;

#define all(a) (a).begin(), (a).end()

void umax(ll &a, ll b){
	a = max(a, b);
}

void solve(){
	int n; cin >> n;
	vector<vector<int>> g(n);
	for(int i=0; i+1<n; i++){
		int u, v; cin >> u >> v;
		u--, v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	string s; cin >> s;
	// active, notactive, best
	// active >= not active
	ll best = 0;
	vector<ll> active(n, -1e9);
	function<void(int, int)> dfs = [&](int u, int p){
		ll sum = 0, mx = 0;
		for(int v:g[u]){
			if(v==p){
				continue;
			}
			dfs(v, u);
			sum += active[v];
			umax(mx, active[v]);
		}
		// activate or not activate
		// activate
		if(s[u]=='1'){
			// not activate childs
			umax(active[u], 1);
			// not activate parents
			umax(best, mx + 1);
		}
		// not activate
		if(s[u]=='1'){
			// broken
			umax(active[u], sum - 1);
		}else{
			umax(active[u], sum);
		}
		debug(active[u]);
	};

	dfs(0, -1);

	cout<<max(best, *max_element(active.begin(), active.end()))<<endl;
}

int main(){
	solve();
	return 0;
}

Compilation message

power.cpp: In lambda function:
power.cpp:6:21: warning: statement has no effect [-Wunused-value]
    6 | #define debug(x...) 0
      |                     ^
power.cpp:58:3: note: in expansion of macro 'debug'
   58 |   debug(active[u]);
      |   ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 436 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 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 604 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 436 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 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 604 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 440 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 1 ms 416 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 560 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 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 560 KB Output is correct
32 Correct 1 ms 348 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 344 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 1 ms 604 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 604 KB Output is correct
46 Correct 1 ms 604 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 1 ms 704 KB Output is correct
50 Correct 2 ms 604 KB Output is correct
51 Correct 1 ms 604 KB Output is correct
52 Correct 1 ms 560 KB Output is correct
53 Correct 1 ms 604 KB Output is correct
54 Correct 1 ms 604 KB Output is correct
55 Correct 2 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 2 ms 604 KB Output is correct
59 Correct 1 ms 600 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Correct 1 ms 348 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 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 436 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 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 604 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 440 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 1 ms 416 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 560 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 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 560 KB Output is correct
32 Correct 1 ms 348 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 344 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 1 ms 604 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 604 KB Output is correct
46 Correct 1 ms 604 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 1 ms 704 KB Output is correct
50 Correct 2 ms 604 KB Output is correct
51 Correct 1 ms 604 KB Output is correct
52 Correct 1 ms 560 KB Output is correct
53 Correct 1 ms 604 KB Output is correct
54 Correct 1 ms 604 KB Output is correct
55 Correct 2 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 2 ms 604 KB Output is correct
59 Correct 1 ms 600 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 1 ms 604 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 98 ms 16096 KB Output is correct
65 Correct 88 ms 16056 KB Output is correct
66 Correct 88 ms 16100 KB Output is correct
67 Correct 95 ms 16004 KB Output is correct
68 Correct 91 ms 16104 KB Output is correct
69 Correct 89 ms 16096 KB Output is correct
70 Correct 96 ms 16100 KB Output is correct
71 Correct 86 ms 15968 KB Output is correct
72 Correct 102 ms 15952 KB Output is correct
73 Correct 96 ms 33760 KB Output is correct
74 Correct 128 ms 33584 KB Output is correct
75 Correct 92 ms 15844 KB Output is correct
76 Correct 91 ms 15840 KB Output is correct
77 Correct 99 ms 15972 KB Output is correct
78 Correct 93 ms 15864 KB Output is correct
79 Correct 87 ms 15840 KB Output is correct
80 Correct 94 ms 15840 KB Output is correct
81 Correct 85 ms 16332 KB Output is correct
82 Correct 87 ms 16080 KB Output is correct
83 Correct 89 ms 23272 KB Output is correct
84 Correct 103 ms 26080 KB Output is correct
85 Correct 91 ms 25680 KB Output is correct
86 Correct 104 ms 18200 KB Output is correct
87 Correct 91 ms 17112 KB Output is correct
88 Correct 90 ms 17380 KB Output is correct
89 Correct 122 ms 17524 KB Output is correct
90 Correct 104 ms 17380 KB Output is correct
91 Correct 89 ms 17632 KB Output is correct
92 Correct 90 ms 17896 KB Output is correct
93 Correct 88 ms 21424 KB Output is correct
94 Correct 94 ms 24012 KB Output is correct
95 Correct 96 ms 22112 KB Output is correct
96 Correct 85 ms 19424 KB Output is correct
97 Correct 83 ms 17392 KB Output is correct
98 Correct 83 ms 16608 KB Output is correct
99 Correct 94 ms 16208 KB Output is correct
100 Correct 92 ms 20788 KB Output is correct
101 Correct 110 ms 17892 KB Output is correct
102 Correct 86 ms 16872 KB Output is correct
103 Correct 100 ms 16612 KB Output is correct
104 Correct 87 ms 16856 KB Output is correct
105 Correct 95 ms 29152 KB Output is correct
106 Correct 72 ms 16584 KB Output is correct
107 Correct 75 ms 16580 KB Output is correct
108 Correct 99 ms 34784 KB Output is correct
109 Correct 75 ms 16836 KB Output is correct
110 Correct 102 ms 35292 KB Output is correct
111 Correct 87 ms 15840 KB Output is correct