Submission #634454

# Submission time Handle Problem Language Result Execution time Memory
634454 2022-08-24T12:45:17 Z ParsaEs Power Plant (JOI20_power) C++17
100 / 100
232 ms 45992 KB
//InTheNameOfGOD
//PRS;)
#pragma GCC optimize("unroll-loops", "O2", "Ofast", "O3")
#pragma GCC target("avx2", "sse", "sse2")
#include<bits/stdc++.h>
#define Fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, l, r) for(ii i = l; i < r; i++)
#define per(i, l, r) for(ii i = r - 1; i >= l; i--)
#define max(x, y) (x > y ? x : y)
#define pb push_back
typedef int ii;
using namespace std;
constexpr ii xn = 2e5 + 5;
vector<ii> g[xn], g1[xn];
ii dd[xn], du[xn], p[xn], s[xn], ans;
char c[xn];
bool f[xn];
void pfs(ii v, ii pa)
{
	ii x = 0;
	for(ii u : g[v]) if(pa != u) pfs(u, v), g1[v].pb(u), x += dd[u];
	g[v].clear();
	if(f[v]) dd[v] = max(x - 1, 1);
	else dd[v] = x;
}
void dfs(ii v)
{
	ii z = g1[v].size();
	p[0] = s[z] = 0;
	rep(i, 0, z) p[i + 1] = dd[g1[v][i]] + p[i];
	per(i, 0, z) s[i] = dd[g1[v][i]] + s[i + 1];
	rep(i, 0, z)
	{
		ii u = g1[v][i];
		ii x = du[v] + p[i] + s[i + 1];
		if(f[v]) du[u] = max(x - 1, 1);
		else du[u] = x;
	}
	if(f[v])
	{
		ans = max(du[v] + 1, ans);
		for(ii u : g1[v]) ans = max(dd[u] + 1, ans);
		ans = max(du[v] + p[z] - 1, ans);
	}
	for(ii u : g1[v]) dfs(u);
}
ii main()
{
	Fast;
	ii n;
	cin >> n;
	ii m = n - 1;
	while(m--)
	{
		ii u, v;
		cin >> u >> v;
		g[--u].pb(--v), g[v].pb(u);
	}
	rep(i, 0, n) cin >> c[i];
	rep(i, 0, n) if(c[i] == '1') f[i] = 1;
	pfs(0, 0), dfs(0);
	cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 7 ms 9684 KB Output is correct
4 Correct 7 ms 9684 KB Output is correct
5 Correct 6 ms 9684 KB Output is correct
6 Correct 7 ms 9720 KB Output is correct
7 Correct 7 ms 9720 KB Output is correct
8 Correct 6 ms 9680 KB Output is correct
9 Correct 6 ms 9684 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 6 ms 9684 KB Output is correct
12 Correct 6 ms 9732 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 6 ms 9720 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 6 ms 9724 KB Output is correct
17 Correct 6 ms 9684 KB Output is correct
18 Correct 7 ms 9788 KB Output is correct
19 Correct 5 ms 9684 KB Output is correct
20 Correct 7 ms 9728 KB Output is correct
21 Correct 5 ms 9724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 7 ms 9684 KB Output is correct
4 Correct 7 ms 9684 KB Output is correct
5 Correct 6 ms 9684 KB Output is correct
6 Correct 7 ms 9720 KB Output is correct
7 Correct 7 ms 9720 KB Output is correct
8 Correct 6 ms 9680 KB Output is correct
9 Correct 6 ms 9684 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 6 ms 9684 KB Output is correct
12 Correct 6 ms 9732 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 6 ms 9720 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 6 ms 9724 KB Output is correct
17 Correct 6 ms 9684 KB Output is correct
18 Correct 7 ms 9788 KB Output is correct
19 Correct 5 ms 9684 KB Output is correct
20 Correct 7 ms 9728 KB Output is correct
21 Correct 5 ms 9724 KB Output is correct
22 Correct 7 ms 9868 KB Output is correct
23 Correct 6 ms 9812 KB Output is correct
24 Correct 7 ms 9812 KB Output is correct
25 Correct 7 ms 9812 KB Output is correct
26 Correct 7 ms 9864 KB Output is correct
27 Correct 8 ms 9812 KB Output is correct
28 Correct 8 ms 9812 KB Output is correct
29 Correct 6 ms 10068 KB Output is correct
30 Correct 6 ms 10000 KB Output is correct
31 Correct 6 ms 9864 KB Output is correct
32 Correct 7 ms 9852 KB Output is correct
33 Correct 6 ms 9812 KB Output is correct
34 Correct 6 ms 9812 KB Output is correct
35 Correct 7 ms 9860 KB Output is correct
36 Correct 6 ms 9812 KB Output is correct
37 Correct 7 ms 9860 KB Output is correct
38 Correct 6 ms 9812 KB Output is correct
39 Correct 7 ms 9940 KB Output is correct
40 Correct 6 ms 9940 KB Output is correct
41 Correct 7 ms 9864 KB Output is correct
42 Correct 6 ms 9812 KB Output is correct
43 Correct 6 ms 9812 KB Output is correct
44 Correct 7 ms 9820 KB Output is correct
45 Correct 6 ms 9884 KB Output is correct
46 Correct 6 ms 9892 KB Output is correct
47 Correct 8 ms 9812 KB Output is correct
48 Correct 7 ms 9988 KB Output is correct
49 Correct 7 ms 9940 KB Output is correct
50 Correct 7 ms 9940 KB Output is correct
51 Correct 7 ms 9940 KB Output is correct
52 Correct 6 ms 9864 KB Output is correct
53 Correct 8 ms 9844 KB Output is correct
54 Correct 6 ms 9812 KB Output is correct
55 Correct 6 ms 9864 KB Output is correct
56 Correct 6 ms 9864 KB Output is correct
57 Correct 7 ms 10040 KB Output is correct
58 Correct 6 ms 9780 KB Output is correct
59 Correct 6 ms 9868 KB Output is correct
60 Correct 6 ms 9992 KB Output is correct
61 Correct 6 ms 9812 KB Output is correct
62 Correct 7 ms 9940 KB Output is correct
63 Correct 6 ms 9812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 7 ms 9684 KB Output is correct
4 Correct 7 ms 9684 KB Output is correct
5 Correct 6 ms 9684 KB Output is correct
6 Correct 7 ms 9720 KB Output is correct
7 Correct 7 ms 9720 KB Output is correct
8 Correct 6 ms 9680 KB Output is correct
9 Correct 6 ms 9684 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 6 ms 9684 KB Output is correct
12 Correct 6 ms 9732 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 6 ms 9720 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 6 ms 9724 KB Output is correct
17 Correct 6 ms 9684 KB Output is correct
18 Correct 7 ms 9788 KB Output is correct
19 Correct 5 ms 9684 KB Output is correct
20 Correct 7 ms 9728 KB Output is correct
21 Correct 5 ms 9724 KB Output is correct
22 Correct 7 ms 9868 KB Output is correct
23 Correct 6 ms 9812 KB Output is correct
24 Correct 7 ms 9812 KB Output is correct
25 Correct 7 ms 9812 KB Output is correct
26 Correct 7 ms 9864 KB Output is correct
27 Correct 8 ms 9812 KB Output is correct
28 Correct 8 ms 9812 KB Output is correct
29 Correct 6 ms 10068 KB Output is correct
30 Correct 6 ms 10000 KB Output is correct
31 Correct 6 ms 9864 KB Output is correct
32 Correct 7 ms 9852 KB Output is correct
33 Correct 6 ms 9812 KB Output is correct
34 Correct 6 ms 9812 KB Output is correct
35 Correct 7 ms 9860 KB Output is correct
36 Correct 6 ms 9812 KB Output is correct
37 Correct 7 ms 9860 KB Output is correct
38 Correct 6 ms 9812 KB Output is correct
39 Correct 7 ms 9940 KB Output is correct
40 Correct 6 ms 9940 KB Output is correct
41 Correct 7 ms 9864 KB Output is correct
42 Correct 6 ms 9812 KB Output is correct
43 Correct 6 ms 9812 KB Output is correct
44 Correct 7 ms 9820 KB Output is correct
45 Correct 6 ms 9884 KB Output is correct
46 Correct 6 ms 9892 KB Output is correct
47 Correct 8 ms 9812 KB Output is correct
48 Correct 7 ms 9988 KB Output is correct
49 Correct 7 ms 9940 KB Output is correct
50 Correct 7 ms 9940 KB Output is correct
51 Correct 7 ms 9940 KB Output is correct
52 Correct 6 ms 9864 KB Output is correct
53 Correct 8 ms 9844 KB Output is correct
54 Correct 6 ms 9812 KB Output is correct
55 Correct 6 ms 9864 KB Output is correct
56 Correct 6 ms 9864 KB Output is correct
57 Correct 7 ms 10040 KB Output is correct
58 Correct 6 ms 9780 KB Output is correct
59 Correct 6 ms 9868 KB Output is correct
60 Correct 6 ms 9992 KB Output is correct
61 Correct 6 ms 9812 KB Output is correct
62 Correct 7 ms 9940 KB Output is correct
63 Correct 6 ms 9812 KB Output is correct
64 Correct 195 ms 24572 KB Output is correct
65 Correct 157 ms 24516 KB Output is correct
66 Correct 166 ms 24528 KB Output is correct
67 Correct 162 ms 24516 KB Output is correct
68 Correct 169 ms 24504 KB Output is correct
69 Correct 150 ms 24468 KB Output is correct
70 Correct 162 ms 24488 KB Output is correct
71 Correct 173 ms 24444 KB Output is correct
72 Correct 158 ms 24412 KB Output is correct
73 Correct 188 ms 44688 KB Output is correct
74 Correct 187 ms 44648 KB Output is correct
75 Correct 176 ms 23892 KB Output is correct
76 Correct 165 ms 23784 KB Output is correct
77 Correct 161 ms 25292 KB Output is correct
78 Correct 183 ms 25420 KB Output is correct
79 Correct 232 ms 25352 KB Output is correct
80 Correct 155 ms 25232 KB Output is correct
81 Correct 126 ms 24504 KB Output is correct
82 Correct 189 ms 24572 KB Output is correct
83 Correct 185 ms 32096 KB Output is correct
84 Correct 199 ms 35116 KB Output is correct
85 Correct 178 ms 34668 KB Output is correct
86 Correct 182 ms 26324 KB Output is correct
87 Correct 150 ms 25564 KB Output is correct
88 Correct 148 ms 26108 KB Output is correct
89 Correct 151 ms 25928 KB Output is correct
90 Correct 169 ms 25620 KB Output is correct
91 Correct 171 ms 26040 KB Output is correct
92 Correct 150 ms 26444 KB Output is correct
93 Correct 141 ms 30208 KB Output is correct
94 Correct 136 ms 32704 KB Output is correct
95 Correct 143 ms 30560 KB Output is correct
96 Correct 179 ms 27896 KB Output is correct
97 Correct 129 ms 25676 KB Output is correct
98 Correct 135 ms 25068 KB Output is correct
99 Correct 154 ms 24832 KB Output is correct
100 Correct 180 ms 29128 KB Output is correct
101 Correct 140 ms 26248 KB Output is correct
102 Correct 135 ms 25252 KB Output is correct
103 Correct 160 ms 25112 KB Output is correct
104 Correct 78 ms 23804 KB Output is correct
105 Correct 179 ms 39984 KB Output is correct
106 Correct 99 ms 23804 KB Output is correct
107 Correct 94 ms 23792 KB Output is correct
108 Correct 182 ms 45544 KB Output is correct
109 Correct 78 ms 23812 KB Output is correct
110 Correct 189 ms 45992 KB Output is correct
111 Correct 155 ms 22676 KB Output is correct