Submission #532239

# Submission time Handle Problem Language Result Execution time Memory
532239 2022-03-02T14:35:54 Z nhdtxdy Power Plant (JOI20_power) C++17
100 / 100
190 ms 28784 KB
//#pragma GCC optimize("Ofast")
//#pragma GCC optimization("unroll-loops, no-stack-protector")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define Snape int main()
#define lumos ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define nox return 0
#define ll long long
#define pb push_back
#define Size(v) (int)v.size()
#define FOR(i, x, y) for(int i = x; i <= y; ++i)
#define trav(a, x) for(auto &a : x)
using namespace std;
using namespace __gnu_pbds;

/*
"After all this time?"
"Always"
*/

const int nax = 2e5+5;
int n, dp[nax];
vector<int> g[nax];
string s;
int ans=0;

void dfs(int v, int p=0) {
	trav(c, g[v]) {
		if (c==p) continue;
		dfs(c, v);
	}
	int val = (s[v]=='1');
	if (val) dp[v] = 1;
	int sum=0;
	trav(c, g[v]) {
		if (c==p) continue;
		sum+=dp[c];
	}
	if (val) {
		dp[v] = max(dp[v], sum - val);
	}
	else dp[v] = max(dp[v], sum);
}

void calc(int v, int p=0) {
	ans=max(ans,dp[v]);
	trav(c, g[v]) {
		if (c==p) continue;
		calc(c, v);
	}
	int val = (s[v]=='1');
	if (val) {
		trav(c, g[v]) {
			if (c == p) continue;
			ans=max(ans,dp[c]+1);
		}
	}
}

int main() {
	lumos;
	cin >> n;
	FOR (i,1,n-1) {
		int a,b; cin>>a>>b;
		g[a].pb(b);
		g[b].pb(a);
	}
	cin >> s; s = ' ' + s;
	dfs(1);
	calc(1);
	cout<<ans;
	nox;
}


# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 3 ms 4980 KB Output is correct
7 Correct 3 ms 5016 KB Output is correct
8 Correct 3 ms 5020 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 4 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 4 ms 5016 KB Output is correct
15 Correct 4 ms 4976 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 5020 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 5016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 3 ms 4980 KB Output is correct
7 Correct 3 ms 5016 KB Output is correct
8 Correct 3 ms 5020 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 4 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 4 ms 5016 KB Output is correct
15 Correct 4 ms 4976 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 5020 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 5016 KB Output is correct
22 Correct 4 ms 5068 KB Output is correct
23 Correct 4 ms 5068 KB Output is correct
24 Correct 4 ms 5016 KB Output is correct
25 Correct 4 ms 5068 KB Output is correct
26 Correct 3 ms 5068 KB Output is correct
27 Correct 4 ms 4988 KB Output is correct
28 Correct 5 ms 5028 KB Output is correct
29 Correct 4 ms 5236 KB Output is correct
30 Correct 4 ms 5196 KB Output is correct
31 Correct 3 ms 5068 KB Output is correct
32 Correct 3 ms 5068 KB Output is correct
33 Correct 4 ms 5068 KB Output is correct
34 Correct 3 ms 5028 KB Output is correct
35 Correct 5 ms 5028 KB Output is correct
36 Correct 4 ms 5028 KB Output is correct
37 Correct 4 ms 5068 KB Output is correct
38 Correct 4 ms 5024 KB Output is correct
39 Correct 4 ms 5068 KB Output is correct
40 Correct 4 ms 5024 KB Output is correct
41 Correct 4 ms 5076 KB Output is correct
42 Correct 4 ms 5068 KB Output is correct
43 Correct 3 ms 5068 KB Output is correct
44 Correct 4 ms 5068 KB Output is correct
45 Correct 3 ms 5024 KB Output is correct
46 Correct 4 ms 5028 KB Output is correct
47 Correct 4 ms 5012 KB Output is correct
48 Correct 3 ms 5068 KB Output is correct
49 Correct 5 ms 5120 KB Output is correct
50 Correct 4 ms 5068 KB Output is correct
51 Correct 3 ms 5068 KB Output is correct
52 Correct 5 ms 5068 KB Output is correct
53 Correct 5 ms 5068 KB Output is correct
54 Correct 5 ms 5076 KB Output is correct
55 Correct 4 ms 5032 KB Output is correct
56 Correct 4 ms 5028 KB Output is correct
57 Correct 4 ms 5196 KB Output is correct
58 Correct 4 ms 5068 KB Output is correct
59 Correct 4 ms 5068 KB Output is correct
60 Correct 4 ms 5068 KB Output is correct
61 Correct 5 ms 5068 KB Output is correct
62 Correct 4 ms 5112 KB Output is correct
63 Correct 3 ms 5068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 3 ms 4980 KB Output is correct
7 Correct 3 ms 5016 KB Output is correct
8 Correct 3 ms 5020 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 4 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 4 ms 5016 KB Output is correct
15 Correct 4 ms 4976 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 5020 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 5016 KB Output is correct
22 Correct 4 ms 5068 KB Output is correct
23 Correct 4 ms 5068 KB Output is correct
24 Correct 4 ms 5016 KB Output is correct
25 Correct 4 ms 5068 KB Output is correct
26 Correct 3 ms 5068 KB Output is correct
27 Correct 4 ms 4988 KB Output is correct
28 Correct 5 ms 5028 KB Output is correct
29 Correct 4 ms 5236 KB Output is correct
30 Correct 4 ms 5196 KB Output is correct
31 Correct 3 ms 5068 KB Output is correct
32 Correct 3 ms 5068 KB Output is correct
33 Correct 4 ms 5068 KB Output is correct
34 Correct 3 ms 5028 KB Output is correct
35 Correct 5 ms 5028 KB Output is correct
36 Correct 4 ms 5028 KB Output is correct
37 Correct 4 ms 5068 KB Output is correct
38 Correct 4 ms 5024 KB Output is correct
39 Correct 4 ms 5068 KB Output is correct
40 Correct 4 ms 5024 KB Output is correct
41 Correct 4 ms 5076 KB Output is correct
42 Correct 4 ms 5068 KB Output is correct
43 Correct 3 ms 5068 KB Output is correct
44 Correct 4 ms 5068 KB Output is correct
45 Correct 3 ms 5024 KB Output is correct
46 Correct 4 ms 5028 KB Output is correct
47 Correct 4 ms 5012 KB Output is correct
48 Correct 3 ms 5068 KB Output is correct
49 Correct 5 ms 5120 KB Output is correct
50 Correct 4 ms 5068 KB Output is correct
51 Correct 3 ms 5068 KB Output is correct
52 Correct 5 ms 5068 KB Output is correct
53 Correct 5 ms 5068 KB Output is correct
54 Correct 5 ms 5076 KB Output is correct
55 Correct 4 ms 5032 KB Output is correct
56 Correct 4 ms 5028 KB Output is correct
57 Correct 4 ms 5196 KB Output is correct
58 Correct 4 ms 5068 KB Output is correct
59 Correct 4 ms 5068 KB Output is correct
60 Correct 4 ms 5068 KB Output is correct
61 Correct 5 ms 5068 KB Output is correct
62 Correct 4 ms 5112 KB Output is correct
63 Correct 3 ms 5068 KB Output is correct
64 Correct 172 ms 15328 KB Output is correct
65 Correct 148 ms 15120 KB Output is correct
66 Correct 170 ms 15200 KB Output is correct
67 Correct 140 ms 15168 KB Output is correct
68 Correct 151 ms 15076 KB Output is correct
69 Correct 140 ms 15072 KB Output is correct
70 Correct 139 ms 15236 KB Output is correct
71 Correct 150 ms 15144 KB Output is correct
72 Correct 138 ms 15192 KB Output is correct
73 Correct 190 ms 27760 KB Output is correct
74 Correct 171 ms 27708 KB Output is correct
75 Correct 126 ms 15080 KB Output is correct
76 Correct 145 ms 15052 KB Output is correct
77 Correct 148 ms 15096 KB Output is correct
78 Correct 179 ms 15024 KB Output is correct
79 Correct 166 ms 15156 KB Output is correct
80 Correct 146 ms 14988 KB Output is correct
81 Correct 103 ms 15456 KB Output is correct
82 Correct 118 ms 15256 KB Output is correct
83 Correct 173 ms 20280 KB Output is correct
84 Correct 167 ms 22384 KB Output is correct
85 Correct 161 ms 22024 KB Output is correct
86 Correct 152 ms 16484 KB Output is correct
87 Correct 163 ms 15876 KB Output is correct
88 Correct 133 ms 16300 KB Output is correct
89 Correct 150 ms 16388 KB Output is correct
90 Correct 130 ms 16116 KB Output is correct
91 Correct 128 ms 16448 KB Output is correct
92 Correct 128 ms 16684 KB Output is correct
93 Correct 132 ms 19148 KB Output is correct
94 Correct 124 ms 20884 KB Output is correct
95 Correct 124 ms 19468 KB Output is correct
96 Correct 122 ms 17792 KB Output is correct
97 Correct 131 ms 16228 KB Output is correct
98 Correct 120 ms 15684 KB Output is correct
99 Correct 124 ms 15472 KB Output is correct
100 Correct 132 ms 18692 KB Output is correct
101 Correct 129 ms 16696 KB Output is correct
102 Correct 122 ms 15968 KB Output is correct
103 Correct 132 ms 15844 KB Output is correct
104 Correct 68 ms 16120 KB Output is correct
105 Correct 159 ms 24508 KB Output is correct
106 Correct 67 ms 15936 KB Output is correct
107 Correct 67 ms 15888 KB Output is correct
108 Correct 169 ms 28556 KB Output is correct
109 Correct 70 ms 16000 KB Output is correct
110 Correct 154 ms 28784 KB Output is correct
111 Correct 114 ms 15024 KB Output is correct