Submission #763101

# Submission time Handle Problem Language Result Execution time Memory
763101 2023-06-22T03:33:06 Z vjudge1 Power Plant (JOI20_power) C++14
100 / 100
111 ms 26764 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 2 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 3 ms 4948 KB Output is correct
6 Correct 2 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 3 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 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 2 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 3 ms 4948 KB Output is correct
6 Correct 2 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 3 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 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 5076 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 5072 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 3 ms 5076 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 4 ms 5096 KB Output is correct
49 Correct 4 ms 5076 KB Output is correct
50 Correct 3 ms 5148 KB Output is correct
51 Correct 3 ms 5076 KB Output is correct
52 Correct 3 ms 5076 KB Output is correct
53 Correct 2 ms 5076 KB Output is correct
54 Correct 2 ms 5076 KB Output is correct
55 Correct 4 ms 5076 KB Output is correct
56 Correct 2 ms 5076 KB Output is correct
57 Correct 3 ms 5132 KB Output is correct
58 Correct 2 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 5204 KB Output is correct
63 Correct 3 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 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 3 ms 4948 KB Output is correct
6 Correct 2 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 3 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 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 5076 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 5072 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 3 ms 5076 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 4 ms 5096 KB Output is correct
49 Correct 4 ms 5076 KB Output is correct
50 Correct 3 ms 5148 KB Output is correct
51 Correct 3 ms 5076 KB Output is correct
52 Correct 3 ms 5076 KB Output is correct
53 Correct 2 ms 5076 KB Output is correct
54 Correct 2 ms 5076 KB Output is correct
55 Correct 4 ms 5076 KB Output is correct
56 Correct 2 ms 5076 KB Output is correct
57 Correct 3 ms 5132 KB Output is correct
58 Correct 2 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 5204 KB Output is correct
63 Correct 3 ms 5076 KB Output is correct
64 Correct 76 ms 14012 KB Output is correct
65 Correct 83 ms 14124 KB Output is correct
66 Correct 84 ms 14028 KB Output is correct
67 Correct 81 ms 14048 KB Output is correct
68 Correct 68 ms 14032 KB Output is correct
69 Correct 67 ms 14092 KB Output is correct
70 Correct 72 ms 14048 KB Output is correct
71 Correct 67 ms 14124 KB Output is correct
72 Correct 111 ms 14028 KB Output is correct
73 Correct 81 ms 25648 KB Output is correct
74 Correct 96 ms 25796 KB Output is correct
75 Correct 87 ms 15308 KB Output is correct
76 Correct 86 ms 15244 KB Output is correct
77 Correct 70 ms 14100 KB Output is correct
78 Correct 73 ms 14028 KB Output is correct
79 Correct 70 ms 14076 KB Output is correct
80 Correct 88 ms 14008 KB Output is correct
81 Correct 59 ms 14004 KB Output is correct
82 Correct 63 ms 14056 KB Output is correct
83 Correct 102 ms 19140 KB Output is correct
84 Correct 78 ms 21336 KB Output is correct
85 Correct 86 ms 20940 KB Output is correct
86 Correct 71 ms 15444 KB Output is correct
87 Correct 103 ms 14772 KB Output is correct
88 Correct 67 ms 14932 KB Output is correct
89 Correct 71 ms 14924 KB Output is correct
90 Correct 105 ms 14800 KB Output is correct
91 Correct 92 ms 14932 KB Output is correct
92 Correct 81 ms 15260 KB Output is correct
93 Correct 79 ms 17472 KB Output is correct
94 Correct 78 ms 19168 KB Output is correct
95 Correct 81 ms 17956 KB Output is correct
96 Correct 67 ms 16044 KB Output is correct
97 Correct 68 ms 14656 KB Output is correct
98 Correct 66 ms 14280 KB Output is correct
99 Correct 67 ms 14148 KB Output is correct
100 Correct 89 ms 17132 KB Output is correct
101 Correct 87 ms 15024 KB Output is correct
102 Correct 81 ms 14316 KB Output is correct
103 Correct 68 ms 14380 KB Output is correct
104 Correct 44 ms 12984 KB Output is correct
105 Correct 78 ms 22476 KB Output is correct
106 Correct 69 ms 14512 KB Output is correct
107 Correct 47 ms 14524 KB Output is correct
108 Correct 106 ms 26504 KB Output is correct
109 Correct 50 ms 12940 KB Output is correct
110 Correct 101 ms 26764 KB Output is correct
111 Correct 63 ms 14028 KB Output is correct