# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1095377 | 2024-10-02T02:46:03 Z | ro9669 | Power Plant (JOI20_power) | C++17 | 79 ms | 28876 KB |
#include <bits/stdc++.h> #define fi first #define se second #define all(v) v.begin() , v.end() #define sz(v) int(v.size()) #define unq(v) sort(all(v)); v.resize(unique(all(v)) - v.begin()); using namespace std; typedef long long ll; typedef pair<int , int> ii; typedef pair<long long , int> lli; const int maxN = int(2e5)+7; const int inf = int(1e9)+7; int n; vector<int> g[maxN]; string s; int dp[maxN] , ans = -inf; void dfs(int u , int par){ dp[u] = (s[u] - '0'); int preSum = 0; for (int v : g[u]){ if (v != par){ dfs(v , u); preSum += max(dp[v] , 0); ans = max(ans , dp[v] + (s[u] - '0')); } } ans = max(ans , preSum - (s[u] - '0')); ans = max(ans , s[u] - '0'); for (int v : g[u]){ if (v != par){ dp[u] = max(dp[u], preSum - max(dp[v] , 0) + dp[v] - (s[u] - '0')); } } } void solve(){ cin >> n; //assert(n <= 2000); for (int i = 1 ; i < n ; i++){ int u , v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } cin >> s; s = '#' + s; for (int i = 1 ; i <= n ; i++){ dfs(i , 0); break; } cout << ans << "\n"; } #define name "A" int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen(name".INP" , "r")){ freopen(name".INP" , "r" , stdin); freopen(name".OUT" , "w" , stdout); } int t = 1; //cin >> t; while (t--) solve(); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4952 KB | Output is correct |
2 | Correct | 2 ms | 4952 KB | Output is correct |
3 | Correct | 2 ms | 4956 KB | Output is correct |
4 | Correct | 2 ms | 4956 KB | Output is correct |
5 | Correct | 2 ms | 4956 KB | Output is correct |
6 | Correct | 2 ms | 4956 KB | Output is correct |
7 | Correct | 2 ms | 4952 KB | Output is correct |
8 | Correct | 2 ms | 4956 KB | Output is correct |
9 | Correct | 2 ms | 5156 KB | Output is correct |
10 | Correct | 2 ms | 4956 KB | Output is correct |
11 | Correct | 2 ms | 4956 KB | Output is correct |
12 | Correct | 3 ms | 4956 KB | Output is correct |
13 | Correct | 2 ms | 4956 KB | Output is correct |
14 | Correct | 2 ms | 4956 KB | Output is correct |
15 | Correct | 2 ms | 4956 KB | Output is correct |
16 | Correct | 2 ms | 4956 KB | Output is correct |
17 | Correct | 2 ms | 4956 KB | Output is correct |
18 | Correct | 2 ms | 4952 KB | Output is correct |
19 | Correct | 2 ms | 4952 KB | Output is correct |
20 | Correct | 2 ms | 4956 KB | Output is correct |
21 | Correct | 2 ms | 4956 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4952 KB | Output is correct |
2 | Correct | 2 ms | 4952 KB | Output is correct |
3 | Correct | 2 ms | 4956 KB | Output is correct |
4 | Correct | 2 ms | 4956 KB | Output is correct |
5 | Correct | 2 ms | 4956 KB | Output is correct |
6 | Correct | 2 ms | 4956 KB | Output is correct |
7 | Correct | 2 ms | 4952 KB | Output is correct |
8 | Correct | 2 ms | 4956 KB | Output is correct |
9 | Correct | 2 ms | 5156 KB | Output is correct |
10 | Correct | 2 ms | 4956 KB | Output is correct |
11 | Correct | 2 ms | 4956 KB | Output is correct |
12 | Correct | 3 ms | 4956 KB | Output is correct |
13 | Correct | 2 ms | 4956 KB | Output is correct |
14 | Correct | 2 ms | 4956 KB | Output is correct |
15 | Correct | 2 ms | 4956 KB | Output is correct |
16 | Correct | 2 ms | 4956 KB | Output is correct |
17 | Correct | 2 ms | 4956 KB | Output is correct |
18 | Correct | 2 ms | 4952 KB | Output is correct |
19 | Correct | 2 ms | 4952 KB | Output is correct |
20 | Correct | 2 ms | 4956 KB | Output is correct |
21 | Correct | 2 ms | 4956 KB | Output is correct |
22 | Correct | 2 ms | 5208 KB | Output is correct |
23 | Correct | 3 ms | 5172 KB | Output is correct |
24 | Correct | 2 ms | 5212 KB | Output is correct |
25 | Correct | 2 ms | 5212 KB | Output is correct |
26 | Correct | 2 ms | 5212 KB | Output is correct |
27 | Correct | 3 ms | 5208 KB | Output is correct |
28 | Correct | 3 ms | 5016 KB | Output is correct |
29 | Correct | 3 ms | 5244 KB | Output is correct |
30 | Correct | 3 ms | 5212 KB | Output is correct |
31 | Correct | 2 ms | 5212 KB | Output is correct |
32 | Correct | 3 ms | 5212 KB | Output is correct |
33 | Correct | 4 ms | 5164 KB | Output is correct |
34 | Correct | 2 ms | 5212 KB | Output is correct |
35 | Correct | 3 ms | 5156 KB | Output is correct |
36 | Correct | 2 ms | 5256 KB | Output is correct |
37 | Correct | 2 ms | 5172 KB | Output is correct |
38 | Correct | 3 ms | 5212 KB | Output is correct |
39 | Correct | 2 ms | 5168 KB | Output is correct |
40 | Correct | 2 ms | 5276 KB | Output is correct |
41 | Correct | 3 ms | 5212 KB | Output is correct |
42 | Correct | 4 ms | 5468 KB | Output is correct |
43 | Correct | 2 ms | 5212 KB | Output is correct |
44 | Correct | 2 ms | 5212 KB | Output is correct |
45 | Correct | 2 ms | 5212 KB | Output is correct |
46 | Correct | 2 ms | 5212 KB | Output is correct |
47 | Correct | 4 ms | 5212 KB | Output is correct |
48 | Correct | 2 ms | 5212 KB | Output is correct |
49 | Correct | 2 ms | 5212 KB | Output is correct |
50 | Correct | 4 ms | 5212 KB | Output is correct |
51 | Correct | 4 ms | 5212 KB | Output is correct |
52 | Correct | 3 ms | 5212 KB | Output is correct |
53 | Correct | 3 ms | 5212 KB | Output is correct |
54 | Correct | 2 ms | 5212 KB | Output is correct |
55 | Correct | 2 ms | 5216 KB | Output is correct |
56 | Correct | 3 ms | 5212 KB | Output is correct |
57 | Correct | 2 ms | 5212 KB | Output is correct |
58 | Correct | 3 ms | 5212 KB | Output is correct |
59 | Correct | 2 ms | 5212 KB | Output is correct |
60 | Correct | 3 ms | 5212 KB | Output is correct |
61 | Correct | 2 ms | 5212 KB | Output is correct |
62 | Correct | 2 ms | 5240 KB | Output is correct |
63 | Correct | 3 ms | 5212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4952 KB | Output is correct |
2 | Correct | 2 ms | 4952 KB | Output is correct |
3 | Correct | 2 ms | 4956 KB | Output is correct |
4 | Correct | 2 ms | 4956 KB | Output is correct |
5 | Correct | 2 ms | 4956 KB | Output is correct |
6 | Correct | 2 ms | 4956 KB | Output is correct |
7 | Correct | 2 ms | 4952 KB | Output is correct |
8 | Correct | 2 ms | 4956 KB | Output is correct |
9 | Correct | 2 ms | 5156 KB | Output is correct |
10 | Correct | 2 ms | 4956 KB | Output is correct |
11 | Correct | 2 ms | 4956 KB | Output is correct |
12 | Correct | 3 ms | 4956 KB | Output is correct |
13 | Correct | 2 ms | 4956 KB | Output is correct |
14 | Correct | 2 ms | 4956 KB | Output is correct |
15 | Correct | 2 ms | 4956 KB | Output is correct |
16 | Correct | 2 ms | 4956 KB | Output is correct |
17 | Correct | 2 ms | 4956 KB | Output is correct |
18 | Correct | 2 ms | 4952 KB | Output is correct |
19 | Correct | 2 ms | 4952 KB | Output is correct |
20 | Correct | 2 ms | 4956 KB | Output is correct |
21 | Correct | 2 ms | 4956 KB | Output is correct |
22 | Correct | 2 ms | 5208 KB | Output is correct |
23 | Correct | 3 ms | 5172 KB | Output is correct |
24 | Correct | 2 ms | 5212 KB | Output is correct |
25 | Correct | 2 ms | 5212 KB | Output is correct |
26 | Correct | 2 ms | 5212 KB | Output is correct |
27 | Correct | 3 ms | 5208 KB | Output is correct |
28 | Correct | 3 ms | 5016 KB | Output is correct |
29 | Correct | 3 ms | 5244 KB | Output is correct |
30 | Correct | 3 ms | 5212 KB | Output is correct |
31 | Correct | 2 ms | 5212 KB | Output is correct |
32 | Correct | 3 ms | 5212 KB | Output is correct |
33 | Correct | 4 ms | 5164 KB | Output is correct |
34 | Correct | 2 ms | 5212 KB | Output is correct |
35 | Correct | 3 ms | 5156 KB | Output is correct |
36 | Correct | 2 ms | 5256 KB | Output is correct |
37 | Correct | 2 ms | 5172 KB | Output is correct |
38 | Correct | 3 ms | 5212 KB | Output is correct |
39 | Correct | 2 ms | 5168 KB | Output is correct |
40 | Correct | 2 ms | 5276 KB | Output is correct |
41 | Correct | 3 ms | 5212 KB | Output is correct |
42 | Correct | 4 ms | 5468 KB | Output is correct |
43 | Correct | 2 ms | 5212 KB | Output is correct |
44 | Correct | 2 ms | 5212 KB | Output is correct |
45 | Correct | 2 ms | 5212 KB | Output is correct |
46 | Correct | 2 ms | 5212 KB | Output is correct |
47 | Correct | 4 ms | 5212 KB | Output is correct |
48 | Correct | 2 ms | 5212 KB | Output is correct |
49 | Correct | 2 ms | 5212 KB | Output is correct |
50 | Correct | 4 ms | 5212 KB | Output is correct |
51 | Correct | 4 ms | 5212 KB | Output is correct |
52 | Correct | 3 ms | 5212 KB | Output is correct |
53 | Correct | 3 ms | 5212 KB | Output is correct |
54 | Correct | 2 ms | 5212 KB | Output is correct |
55 | Correct | 2 ms | 5216 KB | Output is correct |
56 | Correct | 3 ms | 5212 KB | Output is correct |
57 | Correct | 2 ms | 5212 KB | Output is correct |
58 | Correct | 3 ms | 5212 KB | Output is correct |
59 | Correct | 2 ms | 5212 KB | Output is correct |
60 | Correct | 3 ms | 5212 KB | Output is correct |
61 | Correct | 2 ms | 5212 KB | Output is correct |
62 | Correct | 2 ms | 5240 KB | Output is correct |
63 | Correct | 3 ms | 5212 KB | Output is correct |
64 | Correct | 58 ms | 15316 KB | Output is correct |
65 | Correct | 58 ms | 15312 KB | Output is correct |
66 | Correct | 57 ms | 15292 KB | Output is correct |
67 | Correct | 58 ms | 15304 KB | Output is correct |
68 | Correct | 58 ms | 15292 KB | Output is correct |
69 | Correct | 57 ms | 15308 KB | Output is correct |
70 | Correct | 58 ms | 15328 KB | Output is correct |
71 | Correct | 58 ms | 15328 KB | Output is correct |
72 | Correct | 58 ms | 15332 KB | Output is correct |
73 | Correct | 68 ms | 27768 KB | Output is correct |
74 | Correct | 79 ms | 28116 KB | Output is correct |
75 | Correct | 57 ms | 15048 KB | Output is correct |
76 | Correct | 56 ms | 15036 KB | Output is correct |
77 | Correct | 60 ms | 15060 KB | Output is correct |
78 | Correct | 56 ms | 15052 KB | Output is correct |
79 | Correct | 57 ms | 15056 KB | Output is correct |
80 | Correct | 58 ms | 15052 KB | Output is correct |
81 | Correct | 50 ms | 15632 KB | Output is correct |
82 | Correct | 55 ms | 15240 KB | Output is correct |
83 | Correct | 63 ms | 20436 KB | Output is correct |
84 | Correct | 66 ms | 22360 KB | Output is correct |
85 | Correct | 64 ms | 22240 KB | Output is correct |
86 | Correct | 62 ms | 16588 KB | Output is correct |
87 | Correct | 62 ms | 16012 KB | Output is correct |
88 | Correct | 60 ms | 16392 KB | Output is correct |
89 | Correct | 67 ms | 16348 KB | Output is correct |
90 | Correct | 59 ms | 16172 KB | Output is correct |
91 | Correct | 63 ms | 16556 KB | Output is correct |
92 | Correct | 64 ms | 16892 KB | Output is correct |
93 | Correct | 57 ms | 19064 KB | Output is correct |
94 | Correct | 57 ms | 20940 KB | Output is correct |
95 | Correct | 54 ms | 19684 KB | Output is correct |
96 | Correct | 60 ms | 17716 KB | Output is correct |
97 | Correct | 57 ms | 16168 KB | Output is correct |
98 | Correct | 54 ms | 15872 KB | Output is correct |
99 | Correct | 54 ms | 15560 KB | Output is correct |
100 | Correct | 58 ms | 18764 KB | Output is correct |
101 | Correct | 56 ms | 16800 KB | Output is correct |
102 | Correct | 53 ms | 15888 KB | Output is correct |
103 | Correct | 54 ms | 15852 KB | Output is correct |
104 | Correct | 38 ms | 16208 KB | Output is correct |
105 | Correct | 65 ms | 24748 KB | Output is correct |
106 | Correct | 38 ms | 16080 KB | Output is correct |
107 | Correct | 39 ms | 16000 KB | Output is correct |
108 | Correct | 69 ms | 28624 KB | Output is correct |
109 | Correct | 39 ms | 16072 KB | Output is correct |
110 | Correct | 66 ms | 28876 KB | Output is correct |
111 | Correct | 52 ms | 15072 KB | Output is correct |