Submission #534698

# Submission time Handle Problem Language Result Execution time Memory
534698 2022-03-08T14:40:49 Z michao Power Plant (JOI20_power) C++14
100 / 100
1487 ms 46108 KB
#include <bits/stdc++.h>
//#define int long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int MAX=2e5+5;
vi P[MAX];
int c[MAX];
int dp[MAX];
char s[MAX];
int ans=0;

void dfs(int u,int fa){
	vi d;
	d.clear();
	vi wrzut;
	int maxi=0;
	for (auto it:P[u]){
		if (it==fa)continue;
		dfs(it,u);
		d.pb(it);
		maxi=max(maxi,dp[it]);
	}
	
	if (c[u]==0){
		for (auto v:d)dp[u]+=dp[v];
		ans=max(ans,dp[u]);
	}
	else{
		assert(c[u]==1);
		int sum=0;
		for (auto v:d)sum+=dp[v];
		if (sum==0)dp[u]=1,ans=max(ans,dp[u]);
		else{
			dp[u]=max(1,sum-1);
			ans=max(ans,maxi+1);
			ans=max(ans,dp[u]);
		}
	}
}
int32_t main(){
  BOOST;
  int n;
  cin>>n;
  for (int i=1;i<=n-1;i++){
		int a,b;
		cin>>a>>b;
		P[a].pb(b);
		P[b].pb(a);
  }
  for (int i=1;i<=n;i++){
		cin>>s[i];
		c[i]=s[i]-'0';
  }
  dfs(1,-1);
  for (int i=1;i<=n;i++)cerr<<"DPEK "<<i<<" "<<dp[i]<<"\n";
  cout<<ans;
  return 0; 
}

# Verdict Execution time Memory Grader output
1 Correct 4 ms 4972 KB Output is correct
2 Correct 4 ms 4940 KB Output is correct
3 Correct 4 ms 5020 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 4 ms 4940 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 4 ms 5036 KB Output is correct
12 Correct 4 ms 4940 KB Output is correct
13 Correct 4 ms 5024 KB Output is correct
14 Correct 4 ms 4940 KB Output is correct
15 Correct 4 ms 4940 KB Output is correct
16 Correct 4 ms 4920 KB Output is correct
17 Correct 3 ms 4952 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4952 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 4 ms 4940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4972 KB Output is correct
2 Correct 4 ms 4940 KB Output is correct
3 Correct 4 ms 5020 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 4 ms 4940 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 4 ms 5036 KB Output is correct
12 Correct 4 ms 4940 KB Output is correct
13 Correct 4 ms 5024 KB Output is correct
14 Correct 4 ms 4940 KB Output is correct
15 Correct 4 ms 4940 KB Output is correct
16 Correct 4 ms 4920 KB Output is correct
17 Correct 3 ms 4952 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4952 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 4 ms 4940 KB Output is correct
22 Correct 17 ms 5120 KB Output is correct
23 Correct 20 ms 5160 KB Output is correct
24 Correct 17 ms 5160 KB Output is correct
25 Correct 17 ms 5160 KB Output is correct
26 Correct 19 ms 5104 KB Output is correct
27 Correct 17 ms 5144 KB Output is correct
28 Correct 22 ms 5268 KB Output is correct
29 Correct 22 ms 5388 KB Output is correct
30 Correct 16 ms 5324 KB Output is correct
31 Correct 17 ms 5068 KB Output is correct
32 Correct 17 ms 5144 KB Output is correct
33 Correct 22 ms 5164 KB Output is correct
34 Correct 22 ms 5140 KB Output is correct
35 Correct 24 ms 5148 KB Output is correct
36 Correct 16 ms 5160 KB Output is correct
37 Correct 17 ms 5144 KB Output is correct
38 Correct 15 ms 5068 KB Output is correct
39 Correct 16 ms 5196 KB Output is correct
40 Correct 22 ms 5196 KB Output is correct
41 Correct 17 ms 5196 KB Output is correct
42 Correct 17 ms 5196 KB Output is correct
43 Correct 17 ms 5196 KB Output is correct
44 Correct 15 ms 5220 KB Output is correct
45 Correct 17 ms 5196 KB Output is correct
46 Correct 16 ms 5184 KB Output is correct
47 Correct 15 ms 5196 KB Output is correct
48 Correct 20 ms 5196 KB Output is correct
49 Correct 17 ms 5324 KB Output is correct
50 Correct 15 ms 5196 KB Output is correct
51 Correct 16 ms 5204 KB Output is correct
52 Correct 16 ms 5292 KB Output is correct
53 Correct 15 ms 5196 KB Output is correct
54 Correct 15 ms 5164 KB Output is correct
55 Correct 14 ms 5180 KB Output is correct
56 Correct 18 ms 5164 KB Output is correct
57 Correct 17 ms 5432 KB Output is correct
58 Correct 15 ms 5172 KB Output is correct
59 Correct 15 ms 5160 KB Output is correct
60 Correct 16 ms 5296 KB Output is correct
61 Correct 21 ms 5168 KB Output is correct
62 Correct 22 ms 5368 KB Output is correct
63 Correct 16 ms 5040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4972 KB Output is correct
2 Correct 4 ms 4940 KB Output is correct
3 Correct 4 ms 5020 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 4 ms 4940 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 4 ms 5036 KB Output is correct
12 Correct 4 ms 4940 KB Output is correct
13 Correct 4 ms 5024 KB Output is correct
14 Correct 4 ms 4940 KB Output is correct
15 Correct 4 ms 4940 KB Output is correct
16 Correct 4 ms 4920 KB Output is correct
17 Correct 3 ms 4952 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4952 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 4 ms 4940 KB Output is correct
22 Correct 17 ms 5120 KB Output is correct
23 Correct 20 ms 5160 KB Output is correct
24 Correct 17 ms 5160 KB Output is correct
25 Correct 17 ms 5160 KB Output is correct
26 Correct 19 ms 5104 KB Output is correct
27 Correct 17 ms 5144 KB Output is correct
28 Correct 22 ms 5268 KB Output is correct
29 Correct 22 ms 5388 KB Output is correct
30 Correct 16 ms 5324 KB Output is correct
31 Correct 17 ms 5068 KB Output is correct
32 Correct 17 ms 5144 KB Output is correct
33 Correct 22 ms 5164 KB Output is correct
34 Correct 22 ms 5140 KB Output is correct
35 Correct 24 ms 5148 KB Output is correct
36 Correct 16 ms 5160 KB Output is correct
37 Correct 17 ms 5144 KB Output is correct
38 Correct 15 ms 5068 KB Output is correct
39 Correct 16 ms 5196 KB Output is correct
40 Correct 22 ms 5196 KB Output is correct
41 Correct 17 ms 5196 KB Output is correct
42 Correct 17 ms 5196 KB Output is correct
43 Correct 17 ms 5196 KB Output is correct
44 Correct 15 ms 5220 KB Output is correct
45 Correct 17 ms 5196 KB Output is correct
46 Correct 16 ms 5184 KB Output is correct
47 Correct 15 ms 5196 KB Output is correct
48 Correct 20 ms 5196 KB Output is correct
49 Correct 17 ms 5324 KB Output is correct
50 Correct 15 ms 5196 KB Output is correct
51 Correct 16 ms 5204 KB Output is correct
52 Correct 16 ms 5292 KB Output is correct
53 Correct 15 ms 5196 KB Output is correct
54 Correct 15 ms 5164 KB Output is correct
55 Correct 14 ms 5180 KB Output is correct
56 Correct 18 ms 5164 KB Output is correct
57 Correct 17 ms 5432 KB Output is correct
58 Correct 15 ms 5172 KB Output is correct
59 Correct 15 ms 5160 KB Output is correct
60 Correct 16 ms 5296 KB Output is correct
61 Correct 21 ms 5168 KB Output is correct
62 Correct 22 ms 5368 KB Output is correct
63 Correct 16 ms 5040 KB Output is correct
64 Correct 1382 ms 15948 KB Output is correct
65 Correct 1297 ms 15956 KB Output is correct
66 Correct 1355 ms 15972 KB Output is correct
67 Correct 1487 ms 16120 KB Output is correct
68 Correct 1367 ms 15984 KB Output is correct
69 Correct 1329 ms 16020 KB Output is correct
70 Correct 1305 ms 16076 KB Output is correct
71 Correct 1302 ms 16004 KB Output is correct
72 Correct 1276 ms 16008 KB Output is correct
73 Correct 1303 ms 41432 KB Output is correct
74 Correct 1325 ms 41192 KB Output is correct
75 Correct 1306 ms 15832 KB Output is correct
76 Correct 1291 ms 15796 KB Output is correct
77 Correct 1319 ms 16008 KB Output is correct
78 Correct 1286 ms 15776 KB Output is correct
79 Correct 1348 ms 15936 KB Output is correct
80 Correct 1294 ms 15764 KB Output is correct
81 Correct 1262 ms 16460 KB Output is correct
82 Correct 1282 ms 16340 KB Output is correct
83 Correct 1339 ms 27012 KB Output is correct
84 Correct 1299 ms 31412 KB Output is correct
85 Correct 1356 ms 33092 KB Output is correct
86 Correct 1287 ms 21576 KB Output is correct
87 Correct 1294 ms 20188 KB Output is correct
88 Correct 1301 ms 20768 KB Output is correct
89 Correct 1266 ms 20864 KB Output is correct
90 Correct 1290 ms 20260 KB Output is correct
91 Correct 1271 ms 20692 KB Output is correct
92 Correct 1288 ms 21232 KB Output is correct
93 Correct 1265 ms 26756 KB Output is correct
94 Correct 1264 ms 29892 KB Output is correct
95 Correct 1315 ms 27556 KB Output is correct
96 Correct 1270 ms 23676 KB Output is correct
97 Correct 1281 ms 20516 KB Output is correct
98 Correct 1259 ms 19240 KB Output is correct
99 Correct 1269 ms 18920 KB Output is correct
100 Correct 1269 ms 25700 KB Output is correct
101 Correct 1288 ms 21496 KB Output is correct
102 Correct 1265 ms 19708 KB Output is correct
103 Correct 1275 ms 19144 KB Output is correct
104 Correct 1227 ms 18640 KB Output is correct
105 Correct 1298 ms 37484 KB Output is correct
106 Correct 1250 ms 19180 KB Output is correct
107 Correct 1211 ms 19204 KB Output is correct
108 Correct 1313 ms 45496 KB Output is correct
109 Correct 1248 ms 18612 KB Output is correct
110 Correct 1324 ms 46108 KB Output is correct
111 Correct 1292 ms 18484 KB Output is correct