답안 #309037

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
309037 2020-10-02T15:34:28 Z nhdtxdy Power Plant (JOI20_power) C++17
100 / 100
250 ms 26356 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');
	dp[v]=max(dp[v],val);
	int sum=0;
	trav(c, g[v]) {
		if (c==p) continue;
		sum+=dp[c];
	}
	dp[v]=max(dp[v],sum-val);
}

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==0) {
		int sum=0;
		trav(c, g[v]) {
			if (c==p) continue;
			sum+=dp[c];
		}
		ans=max(ans,sum);
	}
	else {
		int sum=0;
		trav(c, g[v]) {
			if (c == p) continue;
			ans=max(ans,dp[c]+1);
			sum+=dp[c];
		}
		ans=max(ans,sum-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;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 5120 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Correct 4 ms 4992 KB Output is correct
6 Correct 4 ms 4992 KB Output is correct
7 Correct 3 ms 4992 KB Output is correct
8 Correct 3 ms 4992 KB Output is correct
9 Correct 4 ms 4992 KB Output is correct
10 Correct 4 ms 4992 KB Output is correct
11 Correct 3 ms 4992 KB Output is correct
12 Correct 3 ms 4992 KB Output is correct
13 Correct 4 ms 4992 KB Output is correct
14 Correct 3 ms 4992 KB Output is correct
15 Correct 3 ms 4992 KB Output is correct
16 Correct 3 ms 4992 KB Output is correct
17 Correct 3 ms 4992 KB Output is correct
18 Correct 4 ms 4992 KB Output is correct
19 Correct 3 ms 4992 KB Output is correct
20 Correct 3 ms 4992 KB Output is correct
21 Correct 4 ms 4992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 5120 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Correct 4 ms 4992 KB Output is correct
6 Correct 4 ms 4992 KB Output is correct
7 Correct 3 ms 4992 KB Output is correct
8 Correct 3 ms 4992 KB Output is correct
9 Correct 4 ms 4992 KB Output is correct
10 Correct 4 ms 4992 KB Output is correct
11 Correct 3 ms 4992 KB Output is correct
12 Correct 3 ms 4992 KB Output is correct
13 Correct 4 ms 4992 KB Output is correct
14 Correct 3 ms 4992 KB Output is correct
15 Correct 3 ms 4992 KB Output is correct
16 Correct 3 ms 4992 KB Output is correct
17 Correct 3 ms 4992 KB Output is correct
18 Correct 4 ms 4992 KB Output is correct
19 Correct 3 ms 4992 KB Output is correct
20 Correct 3 ms 4992 KB Output is correct
21 Correct 4 ms 4992 KB Output is correct
22 Correct 4 ms 5120 KB Output is correct
23 Correct 4 ms 5120 KB Output is correct
24 Correct 4 ms 5120 KB Output is correct
25 Correct 4 ms 5120 KB Output is correct
26 Correct 4 ms 5120 KB Output is correct
27 Correct 4 ms 5120 KB Output is correct
28 Correct 4 ms 5120 KB Output is correct
29 Correct 4 ms 5248 KB Output is correct
30 Correct 4 ms 5248 KB Output is correct
31 Correct 4 ms 5120 KB Output is correct
32 Correct 4 ms 5120 KB Output is correct
33 Correct 4 ms 5120 KB Output is correct
34 Correct 4 ms 5044 KB Output is correct
35 Correct 4 ms 5120 KB Output is correct
36 Correct 4 ms 5120 KB Output is correct
37 Correct 4 ms 5120 KB Output is correct
38 Correct 4 ms 5120 KB Output is correct
39 Correct 4 ms 5120 KB Output is correct
40 Correct 4 ms 5120 KB Output is correct
41 Correct 4 ms 5120 KB Output is correct
42 Correct 4 ms 5120 KB Output is correct
43 Correct 4 ms 5120 KB Output is correct
44 Correct 5 ms 5120 KB Output is correct
45 Correct 4 ms 5120 KB Output is correct
46 Correct 4 ms 5120 KB Output is correct
47 Correct 4 ms 5120 KB Output is correct
48 Correct 4 ms 5120 KB Output is correct
49 Correct 5 ms 5248 KB Output is correct
50 Correct 4 ms 5120 KB Output is correct
51 Correct 4 ms 5120 KB Output is correct
52 Correct 5 ms 5120 KB Output is correct
53 Correct 4 ms 5248 KB Output is correct
54 Correct 4 ms 5120 KB Output is correct
55 Correct 4 ms 5120 KB Output is correct
56 Correct 5 ms 5120 KB Output is correct
57 Correct 4 ms 5248 KB Output is correct
58 Correct 4 ms 5120 KB Output is correct
59 Correct 4 ms 5120 KB Output is correct
60 Correct 4 ms 5120 KB Output is correct
61 Correct 4 ms 5120 KB Output is correct
62 Correct 5 ms 5248 KB Output is correct
63 Correct 4 ms 5120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 5120 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Correct 4 ms 4992 KB Output is correct
6 Correct 4 ms 4992 KB Output is correct
7 Correct 3 ms 4992 KB Output is correct
8 Correct 3 ms 4992 KB Output is correct
9 Correct 4 ms 4992 KB Output is correct
10 Correct 4 ms 4992 KB Output is correct
11 Correct 3 ms 4992 KB Output is correct
12 Correct 3 ms 4992 KB Output is correct
13 Correct 4 ms 4992 KB Output is correct
14 Correct 3 ms 4992 KB Output is correct
15 Correct 3 ms 4992 KB Output is correct
16 Correct 3 ms 4992 KB Output is correct
17 Correct 3 ms 4992 KB Output is correct
18 Correct 4 ms 4992 KB Output is correct
19 Correct 3 ms 4992 KB Output is correct
20 Correct 3 ms 4992 KB Output is correct
21 Correct 4 ms 4992 KB Output is correct
22 Correct 4 ms 5120 KB Output is correct
23 Correct 4 ms 5120 KB Output is correct
24 Correct 4 ms 5120 KB Output is correct
25 Correct 4 ms 5120 KB Output is correct
26 Correct 4 ms 5120 KB Output is correct
27 Correct 4 ms 5120 KB Output is correct
28 Correct 4 ms 5120 KB Output is correct
29 Correct 4 ms 5248 KB Output is correct
30 Correct 4 ms 5248 KB Output is correct
31 Correct 4 ms 5120 KB Output is correct
32 Correct 4 ms 5120 KB Output is correct
33 Correct 4 ms 5120 KB Output is correct
34 Correct 4 ms 5044 KB Output is correct
35 Correct 4 ms 5120 KB Output is correct
36 Correct 4 ms 5120 KB Output is correct
37 Correct 4 ms 5120 KB Output is correct
38 Correct 4 ms 5120 KB Output is correct
39 Correct 4 ms 5120 KB Output is correct
40 Correct 4 ms 5120 KB Output is correct
41 Correct 4 ms 5120 KB Output is correct
42 Correct 4 ms 5120 KB Output is correct
43 Correct 4 ms 5120 KB Output is correct
44 Correct 5 ms 5120 KB Output is correct
45 Correct 4 ms 5120 KB Output is correct
46 Correct 4 ms 5120 KB Output is correct
47 Correct 4 ms 5120 KB Output is correct
48 Correct 4 ms 5120 KB Output is correct
49 Correct 5 ms 5248 KB Output is correct
50 Correct 4 ms 5120 KB Output is correct
51 Correct 4 ms 5120 KB Output is correct
52 Correct 5 ms 5120 KB Output is correct
53 Correct 4 ms 5248 KB Output is correct
54 Correct 4 ms 5120 KB Output is correct
55 Correct 4 ms 5120 KB Output is correct
56 Correct 5 ms 5120 KB Output is correct
57 Correct 4 ms 5248 KB Output is correct
58 Correct 4 ms 5120 KB Output is correct
59 Correct 4 ms 5120 KB Output is correct
60 Correct 4 ms 5120 KB Output is correct
61 Correct 4 ms 5120 KB Output is correct
62 Correct 5 ms 5248 KB Output is correct
63 Correct 4 ms 5120 KB Output is correct
64 Correct 197 ms 12536 KB Output is correct
65 Correct 199 ms 12532 KB Output is correct
66 Correct 200 ms 12512 KB Output is correct
67 Correct 201 ms 12532 KB Output is correct
68 Correct 202 ms 12512 KB Output is correct
69 Correct 205 ms 12528 KB Output is correct
70 Correct 192 ms 12472 KB Output is correct
71 Correct 193 ms 12544 KB Output is correct
72 Correct 205 ms 12528 KB Output is correct
73 Correct 246 ms 25076 KB Output is correct
74 Correct 249 ms 25072 KB Output is correct
75 Correct 193 ms 12404 KB Output is correct
76 Correct 195 ms 12412 KB Output is correct
77 Correct 209 ms 12400 KB Output is correct
78 Correct 201 ms 12428 KB Output is correct
79 Correct 209 ms 12540 KB Output is correct
80 Correct 227 ms 12404 KB Output is correct
81 Correct 159 ms 12916 KB Output is correct
82 Correct 185 ms 12596 KB Output is correct
83 Correct 216 ms 17656 KB Output is correct
84 Correct 220 ms 19712 KB Output is correct
85 Correct 214 ms 19452 KB Output is correct
86 Correct 213 ms 13828 KB Output is correct
87 Correct 198 ms 13296 KB Output is correct
88 Correct 185 ms 13744 KB Output is correct
89 Correct 195 ms 13700 KB Output is correct
90 Correct 185 ms 13528 KB Output is correct
91 Correct 182 ms 13912 KB Output is correct
92 Correct 188 ms 14052 KB Output is correct
93 Correct 188 ms 16576 KB Output is correct
94 Correct 176 ms 18288 KB Output is correct
95 Correct 181 ms 16832 KB Output is correct
96 Correct 185 ms 15072 KB Output is correct
97 Correct 186 ms 13520 KB Output is correct
98 Correct 186 ms 13092 KB Output is correct
99 Correct 186 ms 12912 KB Output is correct
100 Correct 194 ms 15976 KB Output is correct
101 Correct 196 ms 14064 KB Output is correct
102 Correct 177 ms 13248 KB Output is correct
103 Correct 192 ms 13076 KB Output is correct
104 Correct 107 ms 13288 KB Output is correct
105 Correct 245 ms 22004 KB Output is correct
106 Correct 101 ms 13288 KB Output is correct
107 Correct 107 ms 13428 KB Output is correct
108 Correct 243 ms 25844 KB Output is correct
109 Correct 99 ms 13420 KB Output is correct
110 Correct 250 ms 26356 KB Output is correct
111 Correct 187 ms 12384 KB Output is correct