Submission #955907

# Submission time Handle Problem Language Result Execution time Memory
955907 2024-03-31T16:59:50 Z LCJLY Power Plant (JOI20_power) C++14
100 / 100
118 ms 24164 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int long long 
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << "  " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << "  " << j << " " << #i << "  " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<int,int>pii;
typedef pair<pii,pii>pi2;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
 
int n;
vector<int>adj[200005];
 
int best=0;

int dp[200005]; 
string s;

void dfs(int index, int par){
	for(auto it:adj[index]){
		if(it==par) continue;
		dfs(it,index);
	}
	
	int maxi=0;
	for(auto it:adj[index]){
		if(it==par) continue;
		dp[index]+=max(0LL,dp[it]);
		maxi=max(maxi,dp[it]);
	}
	if(s[index]=='1'){
		//show(val,maxi+1);
		best=max(best,maxi+1);
	}
	if(s[index]=='1'){
		dp[index]=max(dp[index]-1,1LL);
	}
	
	
	//show2(index,index,dp[index],dp[index]);
	best=max(best,dp[index]);
}
 
void solve(){
	int n;
	cin >> n;
	int temp,temp2;
	for(int x=0;x<n-1;x++){
		cin >> temp >> temp2;
		adj[temp].push_back(temp2);
		adj[temp2].push_back(temp);
	}
	cin >> s;
	s=" "+s;
	
	dfs(1,-1);
	
	cout << best;
}
 
int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin >> t;
	while(t--){
		solve();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6508 KB Output is correct
3 Correct 3 ms 6492 KB Output is correct
4 Correct 3 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 3 ms 6492 KB Output is correct
8 Correct 3 ms 6492 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6552 KB Output is correct
14 Correct 2 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 2 ms 6488 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6508 KB Output is correct
3 Correct 3 ms 6492 KB Output is correct
4 Correct 3 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 3 ms 6492 KB Output is correct
8 Correct 3 ms 6492 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6552 KB Output is correct
14 Correct 2 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 2 ms 6488 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6488 KB Output is correct
22 Correct 3 ms 6492 KB Output is correct
23 Correct 2 ms 6488 KB Output is correct
24 Correct 3 ms 6488 KB Output is correct
25 Correct 2 ms 6492 KB Output is correct
26 Correct 2 ms 6492 KB Output is correct
27 Correct 2 ms 6492 KB Output is correct
28 Correct 3 ms 6492 KB Output is correct
29 Correct 3 ms 6492 KB Output is correct
30 Correct 3 ms 6492 KB Output is correct
31 Correct 3 ms 6492 KB Output is correct
32 Correct 3 ms 6488 KB Output is correct
33 Correct 2 ms 6492 KB Output is correct
34 Correct 2 ms 6492 KB Output is correct
35 Correct 2 ms 6492 KB Output is correct
36 Correct 3 ms 6492 KB Output is correct
37 Correct 2 ms 6492 KB Output is correct
38 Correct 2 ms 6492 KB Output is correct
39 Correct 3 ms 6492 KB Output is correct
40 Correct 3 ms 6492 KB Output is correct
41 Correct 2 ms 6492 KB Output is correct
42 Correct 3 ms 6492 KB Output is correct
43 Correct 2 ms 6560 KB Output is correct
44 Correct 2 ms 6488 KB Output is correct
45 Correct 2 ms 6556 KB Output is correct
46 Correct 2 ms 6492 KB Output is correct
47 Correct 2 ms 6640 KB Output is correct
48 Correct 2 ms 6740 KB Output is correct
49 Correct 2 ms 6896 KB Output is correct
50 Correct 3 ms 6644 KB Output is correct
51 Correct 2 ms 6492 KB Output is correct
52 Correct 2 ms 6492 KB Output is correct
53 Correct 3 ms 6680 KB Output is correct
54 Correct 2 ms 6492 KB Output is correct
55 Correct 3 ms 6492 KB Output is correct
56 Correct 2 ms 6492 KB Output is correct
57 Correct 2 ms 6744 KB Output is correct
58 Correct 2 ms 6492 KB Output is correct
59 Correct 3 ms 6568 KB Output is correct
60 Correct 3 ms 6492 KB Output is correct
61 Correct 2 ms 6488 KB Output is correct
62 Correct 3 ms 6488 KB Output is correct
63 Correct 4 ms 6488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6508 KB Output is correct
3 Correct 3 ms 6492 KB Output is correct
4 Correct 3 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 3 ms 6492 KB Output is correct
8 Correct 3 ms 6492 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6552 KB Output is correct
14 Correct 2 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 2 ms 6488 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6488 KB Output is correct
22 Correct 3 ms 6492 KB Output is correct
23 Correct 2 ms 6488 KB Output is correct
24 Correct 3 ms 6488 KB Output is correct
25 Correct 2 ms 6492 KB Output is correct
26 Correct 2 ms 6492 KB Output is correct
27 Correct 2 ms 6492 KB Output is correct
28 Correct 3 ms 6492 KB Output is correct
29 Correct 3 ms 6492 KB Output is correct
30 Correct 3 ms 6492 KB Output is correct
31 Correct 3 ms 6492 KB Output is correct
32 Correct 3 ms 6488 KB Output is correct
33 Correct 2 ms 6492 KB Output is correct
34 Correct 2 ms 6492 KB Output is correct
35 Correct 2 ms 6492 KB Output is correct
36 Correct 3 ms 6492 KB Output is correct
37 Correct 2 ms 6492 KB Output is correct
38 Correct 2 ms 6492 KB Output is correct
39 Correct 3 ms 6492 KB Output is correct
40 Correct 3 ms 6492 KB Output is correct
41 Correct 2 ms 6492 KB Output is correct
42 Correct 3 ms 6492 KB Output is correct
43 Correct 2 ms 6560 KB Output is correct
44 Correct 2 ms 6488 KB Output is correct
45 Correct 2 ms 6556 KB Output is correct
46 Correct 2 ms 6492 KB Output is correct
47 Correct 2 ms 6640 KB Output is correct
48 Correct 2 ms 6740 KB Output is correct
49 Correct 2 ms 6896 KB Output is correct
50 Correct 3 ms 6644 KB Output is correct
51 Correct 2 ms 6492 KB Output is correct
52 Correct 2 ms 6492 KB Output is correct
53 Correct 3 ms 6680 KB Output is correct
54 Correct 2 ms 6492 KB Output is correct
55 Correct 3 ms 6492 KB Output is correct
56 Correct 2 ms 6492 KB Output is correct
57 Correct 2 ms 6744 KB Output is correct
58 Correct 2 ms 6492 KB Output is correct
59 Correct 3 ms 6568 KB Output is correct
60 Correct 3 ms 6492 KB Output is correct
61 Correct 2 ms 6488 KB Output is correct
62 Correct 3 ms 6488 KB Output is correct
63 Correct 4 ms 6488 KB Output is correct
64 Correct 108 ms 16972 KB Output is correct
65 Correct 83 ms 17040 KB Output is correct
66 Correct 67 ms 16992 KB Output is correct
67 Correct 86 ms 17004 KB Output is correct
68 Correct 66 ms 17004 KB Output is correct
69 Correct 69 ms 17036 KB Output is correct
70 Correct 67 ms 17056 KB Output is correct
71 Correct 68 ms 17028 KB Output is correct
72 Correct 118 ms 17260 KB Output is correct
73 Correct 93 ms 23480 KB Output is correct
74 Correct 97 ms 23504 KB Output is correct
75 Correct 75 ms 18280 KB Output is correct
76 Correct 99 ms 18200 KB Output is correct
77 Correct 91 ms 17040 KB Output is correct
78 Correct 75 ms 17020 KB Output is correct
79 Correct 76 ms 17044 KB Output is correct
80 Correct 86 ms 17024 KB Output is correct
81 Correct 66 ms 17092 KB Output is correct
82 Correct 67 ms 16900 KB Output is correct
83 Correct 90 ms 19876 KB Output is correct
84 Correct 98 ms 21208 KB Output is correct
85 Correct 89 ms 21132 KB Output is correct
86 Correct 79 ms 17868 KB Output is correct
87 Correct 80 ms 17356 KB Output is correct
88 Correct 82 ms 17676 KB Output is correct
89 Correct 101 ms 17620 KB Output is correct
90 Correct 107 ms 17460 KB Output is correct
91 Correct 69 ms 17584 KB Output is correct
92 Correct 69 ms 17852 KB Output is correct
93 Correct 75 ms 19096 KB Output is correct
94 Correct 99 ms 19908 KB Output is correct
95 Correct 68 ms 18944 KB Output is correct
96 Correct 68 ms 18252 KB Output is correct
97 Correct 69 ms 17248 KB Output is correct
98 Correct 72 ms 17216 KB Output is correct
99 Correct 105 ms 17088 KB Output is correct
100 Correct 83 ms 18632 KB Output is correct
101 Correct 66 ms 17480 KB Output is correct
102 Correct 63 ms 17192 KB Output is correct
103 Correct 74 ms 17332 KB Output is correct
104 Correct 43 ms 17596 KB Output is correct
105 Correct 116 ms 21904 KB Output is correct
106 Correct 51 ms 17604 KB Output is correct
107 Correct 49 ms 17604 KB Output is correct
108 Correct 79 ms 24032 KB Output is correct
109 Correct 44 ms 17600 KB Output is correct
110 Correct 95 ms 24164 KB Output is correct
111 Correct 63 ms 17056 KB Output is correct