Submission #763317

# Submission time Handle Problem Language Result Execution time Memory
763317 2023-06-22T08:08:20 Z vjudge1 Power Plant (JOI20_power) C++17
100 / 100
223 ms 27572 KB
#include<bits/stdc++.h>
using namespace std;

int n, x, y, ans = 0, dp[200001];
vector<int> vec[200001];
string s;
bool visited[200001];

void dfs(int x)
{
	int maxi = 0;
	visited[x] = true;
	for(int c : vec[x])
	{
		if(!visited[c])
		{
			dfs(c);
			dp[x] += dp[c];
			maxi = max(dp[c], maxi);
		}
	}
	dp[x] = max(s[x - 1] - '0', dp[x] - s[x - 1] + '0');
	ans = max(ans, max(maxi + s[x - 1] - '0', dp[x]));
}

int main()
{
	cin >> n;
	for(int i = 1; i < n; ++i)
	{
		cin >> x >> y;
		vec[x].push_back(y);
		vec[y].push_back(x);
	}
	cin >> s;
	dfs(n);
	cout << ans;
}
# 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 3 ms 4948 KB Output is correct
5 Correct 2 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 3 ms 4948 KB Output is correct
11 Correct 2 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 3 ms 4900 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 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 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 3 ms 4948 KB Output is correct
5 Correct 2 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 3 ms 4948 KB Output is correct
11 Correct 2 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 3 ms 4900 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 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 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 5 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 5084 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 4 ms 5076 KB Output is correct
31 Correct 3 ms 5076 KB Output is correct
32 Correct 4 ms 5076 KB Output is correct
33 Correct 3 ms 5088 KB Output is correct
34 Correct 5 ms 5076 KB Output is correct
35 Correct 4 ms 5076 KB Output is correct
36 Correct 3 ms 5052 KB Output is correct
37 Correct 4 ms 5076 KB Output is correct
38 Correct 3 ms 5076 KB Output is correct
39 Correct 5 ms 5028 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 5 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 4 ms 5076 KB Output is correct
48 Correct 3 ms 5076 KB Output is correct
49 Correct 4 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 5092 KB Output is correct
53 Correct 3 ms 5076 KB Output is correct
54 Correct 3 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 5 ms 5196 KB Output is correct
58 Correct 4 ms 5076 KB Output is correct
59 Correct 4 ms 5076 KB Output is correct
60 Correct 3 ms 5204 KB Output is correct
61 Correct 4 ms 5076 KB Output is correct
62 Correct 3 ms 5204 KB Output is correct
63 Correct 3 ms 5064 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 3 ms 4948 KB Output is correct
5 Correct 2 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 3 ms 4948 KB Output is correct
11 Correct 2 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 3 ms 4900 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 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 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 5 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 5084 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 4 ms 5076 KB Output is correct
31 Correct 3 ms 5076 KB Output is correct
32 Correct 4 ms 5076 KB Output is correct
33 Correct 3 ms 5088 KB Output is correct
34 Correct 5 ms 5076 KB Output is correct
35 Correct 4 ms 5076 KB Output is correct
36 Correct 3 ms 5052 KB Output is correct
37 Correct 4 ms 5076 KB Output is correct
38 Correct 3 ms 5076 KB Output is correct
39 Correct 5 ms 5028 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 5 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 4 ms 5076 KB Output is correct
48 Correct 3 ms 5076 KB Output is correct
49 Correct 4 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 5092 KB Output is correct
53 Correct 3 ms 5076 KB Output is correct
54 Correct 3 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 5 ms 5196 KB Output is correct
58 Correct 4 ms 5076 KB Output is correct
59 Correct 4 ms 5076 KB Output is correct
60 Correct 3 ms 5204 KB Output is correct
61 Correct 4 ms 5076 KB Output is correct
62 Correct 3 ms 5204 KB Output is correct
63 Correct 3 ms 5064 KB Output is correct
64 Correct 139 ms 12612 KB Output is correct
65 Correct 145 ms 12640 KB Output is correct
66 Correct 223 ms 12556 KB Output is correct
67 Correct 146 ms 12664 KB Output is correct
68 Correct 138 ms 12620 KB Output is correct
69 Correct 136 ms 12656 KB Output is correct
70 Correct 160 ms 12628 KB Output is correct
71 Correct 195 ms 12636 KB Output is correct
72 Correct 139 ms 12604 KB Output is correct
73 Correct 152 ms 26512 KB Output is correct
74 Correct 152 ms 23904 KB Output is correct
75 Correct 179 ms 12472 KB Output is correct
76 Correct 137 ms 12440 KB Output is correct
77 Correct 130 ms 12480 KB Output is correct
78 Correct 122 ms 12544 KB Output is correct
79 Correct 136 ms 12468 KB Output is correct
80 Correct 126 ms 12532 KB Output is correct
81 Correct 171 ms 13068 KB Output is correct
82 Correct 152 ms 12868 KB Output is correct
83 Correct 130 ms 17476 KB Output is correct
84 Correct 149 ms 18616 KB Output is correct
85 Correct 172 ms 18260 KB Output is correct
86 Correct 139 ms 13916 KB Output is correct
87 Correct 136 ms 14024 KB Output is correct
88 Correct 140 ms 13648 KB Output is correct
89 Correct 203 ms 14080 KB Output is correct
90 Correct 154 ms 13776 KB Output is correct
91 Correct 139 ms 13920 KB Output is correct
92 Correct 145 ms 14076 KB Output is correct
93 Correct 191 ms 18936 KB Output is correct
94 Correct 153 ms 16960 KB Output is correct
95 Correct 152 ms 18924 KB Output is correct
96 Correct 148 ms 16448 KB Output is correct
97 Correct 131 ms 13612 KB Output is correct
98 Correct 135 ms 13132 KB Output is correct
99 Correct 183 ms 12936 KB Output is correct
100 Correct 184 ms 16128 KB Output is correct
101 Correct 123 ms 14212 KB Output is correct
102 Correct 136 ms 13412 KB Output is correct
103 Correct 145 ms 13156 KB Output is correct
104 Correct 124 ms 13328 KB Output is correct
105 Correct 185 ms 23728 KB Output is correct
106 Correct 108 ms 13344 KB Output is correct
107 Correct 100 ms 13340 KB Output is correct
108 Correct 174 ms 24572 KB Output is correct
109 Correct 112 ms 13352 KB Output is correct
110 Correct 193 ms 27572 KB Output is correct
111 Correct 141 ms 12500 KB Output is correct