# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1037883 |
2024-07-29T09:40:05 Z |
phong |
Power Plant (JOI20_power) |
C++17 |
|
68 ms |
30800 KB |
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define ll long long
#define int long long
const int nmax = 2e5 + 5, N = 1e5;
const ll oo = 1e18;
const int lg = 19, M = 2, mod = 1e6;
#define pii pair<ll, ll>
#define fi first
#define se second
#define debug(a, n) for(int i = 1; i <= n; ++i) cout << a[i] << ' '; cout << "\n";
#define endl "\n"
#define task "code"
using namespace std;
int n;
vector<int> adj[nmax];
int a[nmax], dp[nmax], ans = 0;
void dfs(int u, int p){
bool ok = 0, ok2 = 0;
for(auto v : adj[u]){
if(v == p) continue;
dfs(v, u);
dp[u] += dp[v];
ans = max(ans, dp[v] + a[u]);
}
dp[u] -= a[u];
dp[u] = max(dp[u], a[u]);
ans = max(ans, dp[u]);
}
main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
//// freopen(task".inp", "r", stdin);
// freopen(task".out", "w", stdout);
cin >> n;
for(int i = 1; i < n; ++i){
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i = 1; i <= n; ++i){
char x;
cin >> x;
a[i] = (x == '1');
}
dfs(1, -1);
// debug(a, n);
cout << ans;
}
/*
4 3
0 1 1
1 1 0
0 0 0
0 0 0
5
2 2
1 3
3 2
4 3
1 3
*/
Compilation message
power.cpp: In function 'void dfs(long long int, long long int)':
power.cpp:24:10: warning: unused variable 'ok' [-Wunused-variable]
24 | bool ok = 0, ok2 = 0;
| ^~
power.cpp:24:18: warning: unused variable 'ok2' [-Wunused-variable]
24 | bool ok = 0, ok2 = 0;
| ^~~
power.cpp: At global scope:
power.cpp:35:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
35 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8028 KB |
Output is correct |
2 |
Correct |
1 ms |
8028 KB |
Output is correct |
3 |
Correct |
2 ms |
8040 KB |
Output is correct |
4 |
Correct |
1 ms |
8028 KB |
Output is correct |
5 |
Correct |
1 ms |
8024 KB |
Output is correct |
6 |
Correct |
2 ms |
8028 KB |
Output is correct |
7 |
Correct |
2 ms |
8024 KB |
Output is correct |
8 |
Correct |
2 ms |
8028 KB |
Output is correct |
9 |
Correct |
2 ms |
8028 KB |
Output is correct |
10 |
Correct |
2 ms |
8100 KB |
Output is correct |
11 |
Correct |
2 ms |
8028 KB |
Output is correct |
12 |
Correct |
1 ms |
8028 KB |
Output is correct |
13 |
Correct |
2 ms |
8028 KB |
Output is correct |
14 |
Correct |
1 ms |
8104 KB |
Output is correct |
15 |
Correct |
1 ms |
8028 KB |
Output is correct |
16 |
Correct |
1 ms |
8028 KB |
Output is correct |
17 |
Correct |
1 ms |
8028 KB |
Output is correct |
18 |
Correct |
1 ms |
8028 KB |
Output is correct |
19 |
Correct |
2 ms |
8028 KB |
Output is correct |
20 |
Correct |
2 ms |
8028 KB |
Output is correct |
21 |
Correct |
1 ms |
8028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8028 KB |
Output is correct |
2 |
Correct |
1 ms |
8028 KB |
Output is correct |
3 |
Correct |
2 ms |
8040 KB |
Output is correct |
4 |
Correct |
1 ms |
8028 KB |
Output is correct |
5 |
Correct |
1 ms |
8024 KB |
Output is correct |
6 |
Correct |
2 ms |
8028 KB |
Output is correct |
7 |
Correct |
2 ms |
8024 KB |
Output is correct |
8 |
Correct |
2 ms |
8028 KB |
Output is correct |
9 |
Correct |
2 ms |
8028 KB |
Output is correct |
10 |
Correct |
2 ms |
8100 KB |
Output is correct |
11 |
Correct |
2 ms |
8028 KB |
Output is correct |
12 |
Correct |
1 ms |
8028 KB |
Output is correct |
13 |
Correct |
2 ms |
8028 KB |
Output is correct |
14 |
Correct |
1 ms |
8104 KB |
Output is correct |
15 |
Correct |
1 ms |
8028 KB |
Output is correct |
16 |
Correct |
1 ms |
8028 KB |
Output is correct |
17 |
Correct |
1 ms |
8028 KB |
Output is correct |
18 |
Correct |
1 ms |
8028 KB |
Output is correct |
19 |
Correct |
2 ms |
8028 KB |
Output is correct |
20 |
Correct |
2 ms |
8028 KB |
Output is correct |
21 |
Correct |
1 ms |
8028 KB |
Output is correct |
22 |
Correct |
2 ms |
8028 KB |
Output is correct |
23 |
Correct |
3 ms |
8028 KB |
Output is correct |
24 |
Correct |
2 ms |
8028 KB |
Output is correct |
25 |
Correct |
2 ms |
8028 KB |
Output is correct |
26 |
Correct |
2 ms |
8028 KB |
Output is correct |
27 |
Correct |
2 ms |
8028 KB |
Output is correct |
28 |
Correct |
2 ms |
8028 KB |
Output is correct |
29 |
Correct |
2 ms |
8284 KB |
Output is correct |
30 |
Correct |
2 ms |
8284 KB |
Output is correct |
31 |
Correct |
2 ms |
8024 KB |
Output is correct |
32 |
Correct |
2 ms |
8028 KB |
Output is correct |
33 |
Correct |
2 ms |
8028 KB |
Output is correct |
34 |
Correct |
2 ms |
8028 KB |
Output is correct |
35 |
Correct |
2 ms |
8116 KB |
Output is correct |
36 |
Correct |
2 ms |
8028 KB |
Output is correct |
37 |
Correct |
2 ms |
8108 KB |
Output is correct |
38 |
Correct |
2 ms |
8024 KB |
Output is correct |
39 |
Correct |
2 ms |
8396 KB |
Output is correct |
40 |
Correct |
2 ms |
8024 KB |
Output is correct |
41 |
Correct |
2 ms |
8024 KB |
Output is correct |
42 |
Correct |
2 ms |
8024 KB |
Output is correct |
43 |
Correct |
2 ms |
8028 KB |
Output is correct |
44 |
Correct |
2 ms |
8028 KB |
Output is correct |
45 |
Correct |
2 ms |
8028 KB |
Output is correct |
46 |
Correct |
2 ms |
8028 KB |
Output is correct |
47 |
Correct |
2 ms |
8028 KB |
Output is correct |
48 |
Correct |
2 ms |
8284 KB |
Output is correct |
49 |
Correct |
2 ms |
8284 KB |
Output is correct |
50 |
Correct |
2 ms |
8112 KB |
Output is correct |
51 |
Correct |
2 ms |
8196 KB |
Output is correct |
52 |
Correct |
2 ms |
8028 KB |
Output is correct |
53 |
Correct |
2 ms |
8028 KB |
Output is correct |
54 |
Correct |
2 ms |
8028 KB |
Output is correct |
55 |
Correct |
2 ms |
8028 KB |
Output is correct |
56 |
Correct |
2 ms |
8028 KB |
Output is correct |
57 |
Correct |
2 ms |
8284 KB |
Output is correct |
58 |
Correct |
2 ms |
8028 KB |
Output is correct |
59 |
Correct |
2 ms |
8028 KB |
Output is correct |
60 |
Correct |
2 ms |
8028 KB |
Output is correct |
61 |
Correct |
2 ms |
8028 KB |
Output is correct |
62 |
Correct |
2 ms |
8284 KB |
Output is correct |
63 |
Correct |
2 ms |
8024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8028 KB |
Output is correct |
2 |
Correct |
1 ms |
8028 KB |
Output is correct |
3 |
Correct |
2 ms |
8040 KB |
Output is correct |
4 |
Correct |
1 ms |
8028 KB |
Output is correct |
5 |
Correct |
1 ms |
8024 KB |
Output is correct |
6 |
Correct |
2 ms |
8028 KB |
Output is correct |
7 |
Correct |
2 ms |
8024 KB |
Output is correct |
8 |
Correct |
2 ms |
8028 KB |
Output is correct |
9 |
Correct |
2 ms |
8028 KB |
Output is correct |
10 |
Correct |
2 ms |
8100 KB |
Output is correct |
11 |
Correct |
2 ms |
8028 KB |
Output is correct |
12 |
Correct |
1 ms |
8028 KB |
Output is correct |
13 |
Correct |
2 ms |
8028 KB |
Output is correct |
14 |
Correct |
1 ms |
8104 KB |
Output is correct |
15 |
Correct |
1 ms |
8028 KB |
Output is correct |
16 |
Correct |
1 ms |
8028 KB |
Output is correct |
17 |
Correct |
1 ms |
8028 KB |
Output is correct |
18 |
Correct |
1 ms |
8028 KB |
Output is correct |
19 |
Correct |
2 ms |
8028 KB |
Output is correct |
20 |
Correct |
2 ms |
8028 KB |
Output is correct |
21 |
Correct |
1 ms |
8028 KB |
Output is correct |
22 |
Correct |
2 ms |
8028 KB |
Output is correct |
23 |
Correct |
3 ms |
8028 KB |
Output is correct |
24 |
Correct |
2 ms |
8028 KB |
Output is correct |
25 |
Correct |
2 ms |
8028 KB |
Output is correct |
26 |
Correct |
2 ms |
8028 KB |
Output is correct |
27 |
Correct |
2 ms |
8028 KB |
Output is correct |
28 |
Correct |
2 ms |
8028 KB |
Output is correct |
29 |
Correct |
2 ms |
8284 KB |
Output is correct |
30 |
Correct |
2 ms |
8284 KB |
Output is correct |
31 |
Correct |
2 ms |
8024 KB |
Output is correct |
32 |
Correct |
2 ms |
8028 KB |
Output is correct |
33 |
Correct |
2 ms |
8028 KB |
Output is correct |
34 |
Correct |
2 ms |
8028 KB |
Output is correct |
35 |
Correct |
2 ms |
8116 KB |
Output is correct |
36 |
Correct |
2 ms |
8028 KB |
Output is correct |
37 |
Correct |
2 ms |
8108 KB |
Output is correct |
38 |
Correct |
2 ms |
8024 KB |
Output is correct |
39 |
Correct |
2 ms |
8396 KB |
Output is correct |
40 |
Correct |
2 ms |
8024 KB |
Output is correct |
41 |
Correct |
2 ms |
8024 KB |
Output is correct |
42 |
Correct |
2 ms |
8024 KB |
Output is correct |
43 |
Correct |
2 ms |
8028 KB |
Output is correct |
44 |
Correct |
2 ms |
8028 KB |
Output is correct |
45 |
Correct |
2 ms |
8028 KB |
Output is correct |
46 |
Correct |
2 ms |
8028 KB |
Output is correct |
47 |
Correct |
2 ms |
8028 KB |
Output is correct |
48 |
Correct |
2 ms |
8284 KB |
Output is correct |
49 |
Correct |
2 ms |
8284 KB |
Output is correct |
50 |
Correct |
2 ms |
8112 KB |
Output is correct |
51 |
Correct |
2 ms |
8196 KB |
Output is correct |
52 |
Correct |
2 ms |
8028 KB |
Output is correct |
53 |
Correct |
2 ms |
8028 KB |
Output is correct |
54 |
Correct |
2 ms |
8028 KB |
Output is correct |
55 |
Correct |
2 ms |
8028 KB |
Output is correct |
56 |
Correct |
2 ms |
8028 KB |
Output is correct |
57 |
Correct |
2 ms |
8284 KB |
Output is correct |
58 |
Correct |
2 ms |
8028 KB |
Output is correct |
59 |
Correct |
2 ms |
8028 KB |
Output is correct |
60 |
Correct |
2 ms |
8028 KB |
Output is correct |
61 |
Correct |
2 ms |
8028 KB |
Output is correct |
62 |
Correct |
2 ms |
8284 KB |
Output is correct |
63 |
Correct |
2 ms |
8024 KB |
Output is correct |
64 |
Correct |
59 ms |
18260 KB |
Output is correct |
65 |
Correct |
58 ms |
18256 KB |
Output is correct |
66 |
Correct |
54 ms |
18256 KB |
Output is correct |
67 |
Correct |
60 ms |
18260 KB |
Output is correct |
68 |
Correct |
52 ms |
18256 KB |
Output is correct |
69 |
Correct |
53 ms |
18268 KB |
Output is correct |
70 |
Correct |
60 ms |
18260 KB |
Output is correct |
71 |
Correct |
53 ms |
18332 KB |
Output is correct |
72 |
Correct |
51 ms |
18256 KB |
Output is correct |
73 |
Correct |
61 ms |
29864 KB |
Output is correct |
74 |
Correct |
63 ms |
29776 KB |
Output is correct |
75 |
Correct |
54 ms |
19540 KB |
Output is correct |
76 |
Correct |
54 ms |
19424 KB |
Output is correct |
77 |
Correct |
56 ms |
18260 KB |
Output is correct |
78 |
Correct |
56 ms |
18260 KB |
Output is correct |
79 |
Correct |
61 ms |
18372 KB |
Output is correct |
80 |
Correct |
53 ms |
18256 KB |
Output is correct |
81 |
Correct |
47 ms |
18308 KB |
Output is correct |
82 |
Correct |
55 ms |
18124 KB |
Output is correct |
83 |
Correct |
55 ms |
23376 KB |
Output is correct |
84 |
Correct |
68 ms |
25632 KB |
Output is correct |
85 |
Correct |
60 ms |
25012 KB |
Output is correct |
86 |
Correct |
53 ms |
19672 KB |
Output is correct |
87 |
Correct |
54 ms |
19040 KB |
Output is correct |
88 |
Correct |
55 ms |
19176 KB |
Output is correct |
89 |
Correct |
53 ms |
19036 KB |
Output is correct |
90 |
Correct |
59 ms |
19028 KB |
Output is correct |
91 |
Correct |
54 ms |
19204 KB |
Output is correct |
92 |
Correct |
52 ms |
19540 KB |
Output is correct |
93 |
Correct |
51 ms |
21452 KB |
Output is correct |
94 |
Correct |
52 ms |
23236 KB |
Output is correct |
95 |
Correct |
50 ms |
21952 KB |
Output is correct |
96 |
Correct |
55 ms |
20304 KB |
Output is correct |
97 |
Correct |
52 ms |
18772 KB |
Output is correct |
98 |
Correct |
49 ms |
18256 KB |
Output is correct |
99 |
Correct |
51 ms |
18260 KB |
Output is correct |
100 |
Correct |
54 ms |
21192 KB |
Output is correct |
101 |
Correct |
53 ms |
19216 KB |
Output is correct |
102 |
Correct |
48 ms |
18568 KB |
Output is correct |
103 |
Correct |
51 ms |
18416 KB |
Output is correct |
104 |
Correct |
37 ms |
18892 KB |
Output is correct |
105 |
Correct |
59 ms |
26716 KB |
Output is correct |
106 |
Correct |
36 ms |
18624 KB |
Output is correct |
107 |
Correct |
41 ms |
18624 KB |
Output is correct |
108 |
Correct |
61 ms |
30544 KB |
Output is correct |
109 |
Correct |
37 ms |
18880 KB |
Output is correct |
110 |
Correct |
60 ms |
30800 KB |
Output is correct |
111 |
Correct |
48 ms |
18260 KB |
Output is correct |