Submission #763099

# Submission time Handle Problem Language Result Execution time Memory
763099 2023-06-22T03:32:12 Z CESxRhino Power Plant (JOI20_power) C++14
100 / 100
117 ms 26792 KB
#include <bits/stdc++.h>
#define ii pair<int,int>
#define f first
#define s second
#define pb push_back
#define int long long
#define endl '\n'
using namespace std;
const int MAXN = 1e18;
int mod = 1e9 + 7;
int a[200005];
int dp[200005];
bool state[200005];
vector<int> w[200005];
int ans = 0;
void DFS(int u,int par)
{
	int cnt = 0;
	for(int v:w[u])
	{
		if(v == par)
		{
			continue;
		}
		DFS(v,u);
		dp[u] += dp[v];
		cnt = max(cnt,dp[v]);
	}
	if(state[u] == 1)
	{
		ans = max(ans,cnt + 1);
		dp[u] = max(1ll,dp[u] - 1);
	}
	ans = max(ans,dp[u]);
}
void AcSolution()
{
	int n;
	cin >> n;
	for(int i = 1;i < n;i++)
	{
		int u,v;
		cin >> u >> v;
		w[u].push_back(v);
		w[v].push_back(u);
	}
	for(int i = 1;i <= n;i++)
	{
		char x;
		cin >> x;
		if(x == '1')
		{
			state[i] = 1;
		}
		else
		{
			state[i] = 0;
		}
	}
	DFS(1,0);
	cout << ans << endl;
}
signed main()
{
//	freopen("BDIGIT.inp", "r",stdin);
//    freopen("BDIGIT.out", "w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
//	cin >> t;
	while(t--)
	{
	 	AcSolution();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4940 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4972 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4940 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4972 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 3 ms 5076 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 5076 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 3 ms 5076 KB Output is correct
29 Correct 3 ms 5204 KB Output is correct
30 Correct 3 ms 5204 KB Output is correct
31 Correct 3 ms 5076 KB Output is correct
32 Correct 3 ms 5076 KB Output is correct
33 Correct 3 ms 5076 KB Output is correct
34 Correct 3 ms 5076 KB Output is correct
35 Correct 3 ms 5076 KB Output is correct
36 Correct 3 ms 5076 KB Output is correct
37 Correct 3 ms 5076 KB Output is correct
38 Correct 3 ms 5076 KB Output is correct
39 Correct 3 ms 5076 KB Output is correct
40 Correct 3 ms 5076 KB Output is correct
41 Correct 3 ms 5076 KB Output is correct
42 Correct 4 ms 5048 KB Output is correct
43 Correct 3 ms 5076 KB Output is correct
44 Correct 3 ms 5076 KB Output is correct
45 Correct 3 ms 5076 KB Output is correct
46 Correct 3 ms 5076 KB Output is correct
47 Correct 3 ms 5076 KB Output is correct
48 Correct 3 ms 5076 KB Output is correct
49 Correct 3 ms 5076 KB Output is correct
50 Correct 3 ms 5076 KB Output is correct
51 Correct 3 ms 5076 KB Output is correct
52 Correct 3 ms 5076 KB Output is correct
53 Correct 3 ms 5076 KB Output is correct
54 Correct 2 ms 5076 KB Output is correct
55 Correct 3 ms 5076 KB Output is correct
56 Correct 3 ms 5076 KB Output is correct
57 Correct 3 ms 5204 KB Output is correct
58 Correct 3 ms 5076 KB Output is correct
59 Correct 3 ms 5076 KB Output is correct
60 Correct 3 ms 5076 KB Output is correct
61 Correct 3 ms 5076 KB Output is correct
62 Correct 3 ms 5216 KB Output is correct
63 Correct 3 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4940 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4972 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 3 ms 5076 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 5076 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 3 ms 5076 KB Output is correct
29 Correct 3 ms 5204 KB Output is correct
30 Correct 3 ms 5204 KB Output is correct
31 Correct 3 ms 5076 KB Output is correct
32 Correct 3 ms 5076 KB Output is correct
33 Correct 3 ms 5076 KB Output is correct
34 Correct 3 ms 5076 KB Output is correct
35 Correct 3 ms 5076 KB Output is correct
36 Correct 3 ms 5076 KB Output is correct
37 Correct 3 ms 5076 KB Output is correct
38 Correct 3 ms 5076 KB Output is correct
39 Correct 3 ms 5076 KB Output is correct
40 Correct 3 ms 5076 KB Output is correct
41 Correct 3 ms 5076 KB Output is correct
42 Correct 4 ms 5048 KB Output is correct
43 Correct 3 ms 5076 KB Output is correct
44 Correct 3 ms 5076 KB Output is correct
45 Correct 3 ms 5076 KB Output is correct
46 Correct 3 ms 5076 KB Output is correct
47 Correct 3 ms 5076 KB Output is correct
48 Correct 3 ms 5076 KB Output is correct
49 Correct 3 ms 5076 KB Output is correct
50 Correct 3 ms 5076 KB Output is correct
51 Correct 3 ms 5076 KB Output is correct
52 Correct 3 ms 5076 KB Output is correct
53 Correct 3 ms 5076 KB Output is correct
54 Correct 2 ms 5076 KB Output is correct
55 Correct 3 ms 5076 KB Output is correct
56 Correct 3 ms 5076 KB Output is correct
57 Correct 3 ms 5204 KB Output is correct
58 Correct 3 ms 5076 KB Output is correct
59 Correct 3 ms 5076 KB Output is correct
60 Correct 3 ms 5076 KB Output is correct
61 Correct 3 ms 5076 KB Output is correct
62 Correct 3 ms 5216 KB Output is correct
63 Correct 3 ms 5076 KB Output is correct
64 Correct 70 ms 14112 KB Output is correct
65 Correct 81 ms 14120 KB Output is correct
66 Correct 89 ms 14124 KB Output is correct
67 Correct 64 ms 14040 KB Output is correct
68 Correct 69 ms 14112 KB Output is correct
69 Correct 70 ms 14028 KB Output is correct
70 Correct 76 ms 14028 KB Output is correct
71 Correct 98 ms 14124 KB Output is correct
72 Correct 68 ms 14100 KB Output is correct
73 Correct 103 ms 25636 KB Output is correct
74 Correct 108 ms 25600 KB Output is correct
75 Correct 69 ms 15276 KB Output is correct
76 Correct 70 ms 15316 KB Output is correct
77 Correct 73 ms 14072 KB Output is correct
78 Correct 70 ms 14008 KB Output is correct
79 Correct 67 ms 14048 KB Output is correct
80 Correct 68 ms 14092 KB Output is correct
81 Correct 68 ms 14080 KB Output is correct
82 Correct 63 ms 14004 KB Output is correct
83 Correct 117 ms 19096 KB Output is correct
84 Correct 79 ms 21292 KB Output is correct
85 Correct 92 ms 21012 KB Output is correct
86 Correct 96 ms 15504 KB Output is correct
87 Correct 89 ms 14860 KB Output is correct
88 Correct 67 ms 14928 KB Output is correct
89 Correct 67 ms 14924 KB Output is correct
90 Correct 71 ms 14804 KB Output is correct
91 Correct 77 ms 14928 KB Output is correct
92 Correct 77 ms 15348 KB Output is correct
93 Correct 77 ms 17564 KB Output is correct
94 Correct 68 ms 19252 KB Output is correct
95 Correct 68 ms 17856 KB Output is correct
96 Correct 68 ms 16044 KB Output is correct
97 Correct 83 ms 14716 KB Output is correct
98 Correct 68 ms 14292 KB Output is correct
99 Correct 67 ms 14116 KB Output is correct
100 Correct 68 ms 17036 KB Output is correct
101 Correct 67 ms 14924 KB Output is correct
102 Correct 68 ms 14416 KB Output is correct
103 Correct 69 ms 14404 KB Output is correct
104 Correct 65 ms 13028 KB Output is correct
105 Correct 101 ms 22512 KB Output is correct
106 Correct 46 ms 14520 KB Output is correct
107 Correct 45 ms 14544 KB Output is correct
108 Correct 80 ms 26500 KB Output is correct
109 Correct 44 ms 12996 KB Output is correct
110 Correct 80 ms 26792 KB Output is correct
111 Correct 65 ms 14028 KB Output is correct