Submission #1031125

# Submission time Handle Problem Language Result Execution time Memory
1031125 2024-07-22T15:14:56 Z vjudge1 Power Plant (JOI20_power) C++17
100 / 100
70 ms 31632 KB
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pld pair<ld, ld>
#define pb push_back
#define fi first
#define se second
#define debug(x) cout << #x << " => " << x << endl
#define all(x) x.begin(),x.end()

vector<int> adj[200010];
string s;
int ans;
int dp[200010];

void dfs(int u,int p)
{
	int sum=0,mx=0;
	for(auto i : adj[u])
	{
		if(i!=p)
		{
			dfs(i,u);
			sum+=dp[i];
			mx=max(mx,dp[i]);
		}
	}
	if(s[u-1]=='0') dp[u]=sum;
	else
	{
		dp[u]=max(1,sum-1);
		ans=max(ans,mx+1);
	}
	ans=max(ans,dp[u]);
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n;cin>>n;
	for(int i=1;i<n;i++)
	{
		int u,v;cin>>u>>v;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	cin>>s;
	dfs(1,-1);
	cout<<ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5720 KB Output is correct
2 Correct 2 ms 5720 KB Output is correct
3 Correct 2 ms 5724 KB Output is correct
4 Correct 2 ms 5724 KB Output is correct
5 Correct 2 ms 5720 KB Output is correct
6 Correct 2 ms 5536 KB Output is correct
7 Correct 2 ms 5724 KB Output is correct
8 Correct 2 ms 5720 KB Output is correct
9 Correct 2 ms 5724 KB Output is correct
10 Correct 2 ms 5768 KB Output is correct
11 Correct 2 ms 5724 KB Output is correct
12 Correct 2 ms 5724 KB Output is correct
13 Correct 2 ms 5724 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 2 ms 5720 KB Output is correct
16 Correct 2 ms 5724 KB Output is correct
17 Correct 3 ms 5724 KB Output is correct
18 Correct 2 ms 5724 KB Output is correct
19 Correct 2 ms 5724 KB Output is correct
20 Correct 2 ms 5724 KB Output is correct
21 Correct 2 ms 5724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5720 KB Output is correct
2 Correct 2 ms 5720 KB Output is correct
3 Correct 2 ms 5724 KB Output is correct
4 Correct 2 ms 5724 KB Output is correct
5 Correct 2 ms 5720 KB Output is correct
6 Correct 2 ms 5536 KB Output is correct
7 Correct 2 ms 5724 KB Output is correct
8 Correct 2 ms 5720 KB Output is correct
9 Correct 2 ms 5724 KB Output is correct
10 Correct 2 ms 5768 KB Output is correct
11 Correct 2 ms 5724 KB Output is correct
12 Correct 2 ms 5724 KB Output is correct
13 Correct 2 ms 5724 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 2 ms 5720 KB Output is correct
16 Correct 2 ms 5724 KB Output is correct
17 Correct 3 ms 5724 KB Output is correct
18 Correct 2 ms 5724 KB Output is correct
19 Correct 2 ms 5724 KB Output is correct
20 Correct 2 ms 5724 KB Output is correct
21 Correct 2 ms 5724 KB Output is correct
22 Correct 2 ms 5724 KB Output is correct
23 Correct 2 ms 5724 KB Output is correct
24 Correct 2 ms 5776 KB Output is correct
25 Correct 2 ms 5724 KB Output is correct
26 Correct 2 ms 5724 KB Output is correct
27 Correct 2 ms 5720 KB Output is correct
28 Correct 2 ms 5724 KB Output is correct
29 Correct 2 ms 5980 KB Output is correct
30 Correct 2 ms 5724 KB Output is correct
31 Correct 2 ms 5724 KB Output is correct
32 Correct 2 ms 5720 KB Output is correct
33 Correct 2 ms 5724 KB Output is correct
34 Correct 2 ms 5976 KB Output is correct
35 Correct 2 ms 5720 KB Output is correct
36 Correct 2 ms 5724 KB Output is correct
37 Correct 2 ms 5724 KB Output is correct
38 Correct 3 ms 5724 KB Output is correct
39 Correct 2 ms 5724 KB Output is correct
40 Correct 2 ms 5724 KB Output is correct
41 Correct 2 ms 5720 KB Output is correct
42 Correct 2 ms 5724 KB Output is correct
43 Correct 2 ms 5720 KB Output is correct
44 Correct 3 ms 5976 KB Output is correct
45 Correct 2 ms 5772 KB Output is correct
46 Correct 2 ms 5728 KB Output is correct
47 Correct 3 ms 5848 KB Output is correct
48 Correct 3 ms 5724 KB Output is correct
49 Correct 2 ms 5720 KB Output is correct
50 Correct 2 ms 5720 KB Output is correct
51 Correct 3 ms 5724 KB Output is correct
52 Correct 2 ms 5724 KB Output is correct
53 Correct 2 ms 5724 KB Output is correct
54 Correct 2 ms 5720 KB Output is correct
55 Correct 2 ms 5724 KB Output is correct
56 Correct 3 ms 5720 KB Output is correct
57 Correct 2 ms 5980 KB Output is correct
58 Correct 2 ms 5724 KB Output is correct
59 Correct 2 ms 5852 KB Output is correct
60 Correct 2 ms 5824 KB Output is correct
61 Correct 2 ms 5720 KB Output is correct
62 Correct 2 ms 5976 KB Output is correct
63 Correct 2 ms 5776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5720 KB Output is correct
2 Correct 2 ms 5720 KB Output is correct
3 Correct 2 ms 5724 KB Output is correct
4 Correct 2 ms 5724 KB Output is correct
5 Correct 2 ms 5720 KB Output is correct
6 Correct 2 ms 5536 KB Output is correct
7 Correct 2 ms 5724 KB Output is correct
8 Correct 2 ms 5720 KB Output is correct
9 Correct 2 ms 5724 KB Output is correct
10 Correct 2 ms 5768 KB Output is correct
11 Correct 2 ms 5724 KB Output is correct
12 Correct 2 ms 5724 KB Output is correct
13 Correct 2 ms 5724 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 2 ms 5720 KB Output is correct
16 Correct 2 ms 5724 KB Output is correct
17 Correct 3 ms 5724 KB Output is correct
18 Correct 2 ms 5724 KB Output is correct
19 Correct 2 ms 5724 KB Output is correct
20 Correct 2 ms 5724 KB Output is correct
21 Correct 2 ms 5724 KB Output is correct
22 Correct 2 ms 5724 KB Output is correct
23 Correct 2 ms 5724 KB Output is correct
24 Correct 2 ms 5776 KB Output is correct
25 Correct 2 ms 5724 KB Output is correct
26 Correct 2 ms 5724 KB Output is correct
27 Correct 2 ms 5720 KB Output is correct
28 Correct 2 ms 5724 KB Output is correct
29 Correct 2 ms 5980 KB Output is correct
30 Correct 2 ms 5724 KB Output is correct
31 Correct 2 ms 5724 KB Output is correct
32 Correct 2 ms 5720 KB Output is correct
33 Correct 2 ms 5724 KB Output is correct
34 Correct 2 ms 5976 KB Output is correct
35 Correct 2 ms 5720 KB Output is correct
36 Correct 2 ms 5724 KB Output is correct
37 Correct 2 ms 5724 KB Output is correct
38 Correct 3 ms 5724 KB Output is correct
39 Correct 2 ms 5724 KB Output is correct
40 Correct 2 ms 5724 KB Output is correct
41 Correct 2 ms 5720 KB Output is correct
42 Correct 2 ms 5724 KB Output is correct
43 Correct 2 ms 5720 KB Output is correct
44 Correct 3 ms 5976 KB Output is correct
45 Correct 2 ms 5772 KB Output is correct
46 Correct 2 ms 5728 KB Output is correct
47 Correct 3 ms 5848 KB Output is correct
48 Correct 3 ms 5724 KB Output is correct
49 Correct 2 ms 5720 KB Output is correct
50 Correct 2 ms 5720 KB Output is correct
51 Correct 3 ms 5724 KB Output is correct
52 Correct 2 ms 5724 KB Output is correct
53 Correct 2 ms 5724 KB Output is correct
54 Correct 2 ms 5720 KB Output is correct
55 Correct 2 ms 5724 KB Output is correct
56 Correct 3 ms 5720 KB Output is correct
57 Correct 2 ms 5980 KB Output is correct
58 Correct 2 ms 5724 KB Output is correct
59 Correct 2 ms 5852 KB Output is correct
60 Correct 2 ms 5824 KB Output is correct
61 Correct 2 ms 5720 KB Output is correct
62 Correct 2 ms 5976 KB Output is correct
63 Correct 2 ms 5776 KB Output is correct
64 Correct 53 ms 15252 KB Output is correct
65 Correct 51 ms 15252 KB Output is correct
66 Correct 54 ms 15228 KB Output is correct
67 Correct 52 ms 15256 KB Output is correct
68 Correct 52 ms 15196 KB Output is correct
69 Correct 52 ms 15248 KB Output is correct
70 Correct 54 ms 15264 KB Output is correct
71 Correct 52 ms 15260 KB Output is correct
72 Correct 52 ms 15304 KB Output is correct
73 Correct 67 ms 30352 KB Output is correct
74 Correct 70 ms 30352 KB Output is correct
75 Correct 51 ms 15160 KB Output is correct
76 Correct 54 ms 15160 KB Output is correct
77 Correct 54 ms 15152 KB Output is correct
78 Correct 57 ms 15160 KB Output is correct
79 Correct 54 ms 15164 KB Output is correct
80 Correct 51 ms 15152 KB Output is correct
81 Correct 49 ms 15560 KB Output is correct
82 Correct 52 ms 15408 KB Output is correct
83 Correct 57 ms 21400 KB Output is correct
84 Correct 60 ms 23968 KB Output is correct
85 Correct 61 ms 23460 KB Output is correct
86 Correct 69 ms 16828 KB Output is correct
87 Correct 51 ms 16280 KB Output is correct
88 Correct 53 ms 16512 KB Output is correct
89 Correct 53 ms 16544 KB Output is correct
90 Correct 54 ms 16364 KB Output is correct
91 Correct 54 ms 16544 KB Output is correct
92 Correct 55 ms 17024 KB Output is correct
93 Correct 59 ms 19784 KB Output is correct
94 Correct 51 ms 21960 KB Output is correct
95 Correct 51 ms 20336 KB Output is correct
96 Correct 55 ms 18180 KB Output is correct
97 Correct 53 ms 16364 KB Output is correct
98 Correct 57 ms 15812 KB Output is correct
99 Correct 51 ms 15500 KB Output is correct
100 Correct 53 ms 19324 KB Output is correct
101 Correct 53 ms 16952 KB Output is correct
102 Correct 51 ms 15968 KB Output is correct
103 Correct 53 ms 15764 KB Output is correct
104 Correct 42 ms 16000 KB Output is correct
105 Correct 62 ms 26512 KB Output is correct
106 Correct 36 ms 15944 KB Output is correct
107 Correct 36 ms 16072 KB Output is correct
108 Correct 65 ms 31380 KB Output is correct
109 Correct 39 ms 16080 KB Output is correct
110 Correct 64 ms 31632 KB Output is correct
111 Correct 49 ms 15164 KB Output is correct