# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
914565 |
2024-01-22T10:45:17 Z |
qin |
Power Plant (JOI20_power) |
C++17 |
|
137 ms |
23860 KB |
#include <bits/stdc++.h>
#define fi first
#define se second
#define ssize(x) int(x.size())
#define pn printf("\n");
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vv vector
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int inf = 2e09; ll infll = 2e18; int mod = 119<<23|1;
struct graph{
vector<vector<int>> g;
vector<int> dp, pp;
void init(int n){
g.resize(n+1), dp.resize(n+1), pp.resize(n+1);
}
void add_edge(int a, int b){ g[a].emplace_back(b), g[b].emplace_back(a); }
int result = 0;
void dfs(int x, int par){
int sum = 0;
for(int u : g[x]) if(u != par) dfs(u, x), sum += dp[u];
if(!pp[x]){ dp[x] = max(sum, 0), result = max(result, dp[x]); return; }
for(int u : g[x]) result = max(result, dp[u]+1);
dp[x] = max(sum-1, 1), result = max(result, dp[x]);
}
};
void answer(){
int n; scanf("%d", &n);
graph g; g.init(n);
for(int i = 0; i < n-1; ++i){
int a, b; scanf("%d%d", &a, &b);
g.add_edge(a, b);
}
char c = getchar_unlocked();
for(int i = 1; i <= n; ++i) c = getchar_unlocked(), g.pp[i] = c-'0';
g.dfs(1, 0);
printf("%d\n", g.result);
}
int main(){
int T = 1;
for(++T; --T; ) answer();
return 0;
}
Compilation message
power.cpp: In function 'void answer()':
power.cpp:30:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | int n; scanf("%d", &n);
| ~~~~~^~~~~~~~~~
power.cpp:33:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | int a, b; scanf("%d%d", &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
600 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
600 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
448 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
2 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
448 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
604 KB |
Output is correct |
40 |
Correct |
1 ms |
604 KB |
Output is correct |
41 |
Correct |
1 ms |
604 KB |
Output is correct |
42 |
Correct |
1 ms |
444 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
1 ms |
604 KB |
Output is correct |
45 |
Correct |
1 ms |
544 KB |
Output is correct |
46 |
Correct |
1 ms |
348 KB |
Output is correct |
47 |
Correct |
1 ms |
452 KB |
Output is correct |
48 |
Correct |
1 ms |
604 KB |
Output is correct |
49 |
Correct |
1 ms |
604 KB |
Output is correct |
50 |
Correct |
1 ms |
604 KB |
Output is correct |
51 |
Correct |
1 ms |
604 KB |
Output is correct |
52 |
Correct |
1 ms |
348 KB |
Output is correct |
53 |
Correct |
1 ms |
604 KB |
Output is correct |
54 |
Correct |
1 ms |
348 KB |
Output is correct |
55 |
Correct |
1 ms |
348 KB |
Output is correct |
56 |
Correct |
1 ms |
344 KB |
Output is correct |
57 |
Correct |
1 ms |
604 KB |
Output is correct |
58 |
Correct |
1 ms |
348 KB |
Output is correct |
59 |
Correct |
1 ms |
344 KB |
Output is correct |
60 |
Correct |
1 ms |
600 KB |
Output is correct |
61 |
Correct |
1 ms |
344 KB |
Output is correct |
62 |
Correct |
1 ms |
604 KB |
Output is correct |
63 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
600 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
448 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
2 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
448 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
604 KB |
Output is correct |
40 |
Correct |
1 ms |
604 KB |
Output is correct |
41 |
Correct |
1 ms |
604 KB |
Output is correct |
42 |
Correct |
1 ms |
444 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
1 ms |
604 KB |
Output is correct |
45 |
Correct |
1 ms |
544 KB |
Output is correct |
46 |
Correct |
1 ms |
348 KB |
Output is correct |
47 |
Correct |
1 ms |
452 KB |
Output is correct |
48 |
Correct |
1 ms |
604 KB |
Output is correct |
49 |
Correct |
1 ms |
604 KB |
Output is correct |
50 |
Correct |
1 ms |
604 KB |
Output is correct |
51 |
Correct |
1 ms |
604 KB |
Output is correct |
52 |
Correct |
1 ms |
348 KB |
Output is correct |
53 |
Correct |
1 ms |
604 KB |
Output is correct |
54 |
Correct |
1 ms |
348 KB |
Output is correct |
55 |
Correct |
1 ms |
348 KB |
Output is correct |
56 |
Correct |
1 ms |
344 KB |
Output is correct |
57 |
Correct |
1 ms |
604 KB |
Output is correct |
58 |
Correct |
1 ms |
348 KB |
Output is correct |
59 |
Correct |
1 ms |
344 KB |
Output is correct |
60 |
Correct |
1 ms |
600 KB |
Output is correct |
61 |
Correct |
1 ms |
344 KB |
Output is correct |
62 |
Correct |
1 ms |
604 KB |
Output is correct |
63 |
Correct |
1 ms |
348 KB |
Output is correct |
64 |
Correct |
83 ms |
15524 KB |
Output is correct |
65 |
Correct |
137 ms |
15652 KB |
Output is correct |
66 |
Correct |
80 ms |
15764 KB |
Output is correct |
67 |
Correct |
105 ms |
15776 KB |
Output is correct |
68 |
Correct |
73 ms |
15700 KB |
Output is correct |
69 |
Correct |
71 ms |
15572 KB |
Output is correct |
70 |
Correct |
82 ms |
15772 KB |
Output is correct |
71 |
Correct |
83 ms |
15704 KB |
Output is correct |
72 |
Correct |
118 ms |
15764 KB |
Output is correct |
73 |
Correct |
91 ms |
23124 KB |
Output is correct |
74 |
Correct |
135 ms |
23220 KB |
Output is correct |
75 |
Correct |
89 ms |
15440 KB |
Output is correct |
76 |
Correct |
107 ms |
15440 KB |
Output is correct |
77 |
Correct |
76 ms |
15544 KB |
Output is correct |
78 |
Correct |
71 ms |
15436 KB |
Output is correct |
79 |
Correct |
70 ms |
15440 KB |
Output is correct |
80 |
Correct |
88 ms |
15476 KB |
Output is correct |
81 |
Correct |
106 ms |
16228 KB |
Output is correct |
82 |
Correct |
92 ms |
15824 KB |
Output is correct |
83 |
Correct |
91 ms |
18616 KB |
Output is correct |
84 |
Correct |
104 ms |
20064 KB |
Output is correct |
85 |
Correct |
101 ms |
19796 KB |
Output is correct |
86 |
Correct |
80 ms |
16468 KB |
Output is correct |
87 |
Correct |
73 ms |
16208 KB |
Output is correct |
88 |
Correct |
84 ms |
16724 KB |
Output is correct |
89 |
Correct |
131 ms |
17128 KB |
Output is correct |
90 |
Correct |
90 ms |
16468 KB |
Output is correct |
91 |
Correct |
78 ms |
16724 KB |
Output is correct |
92 |
Correct |
129 ms |
16724 KB |
Output is correct |
93 |
Correct |
109 ms |
18124 KB |
Output is correct |
94 |
Correct |
118 ms |
19144 KB |
Output is correct |
95 |
Correct |
90 ms |
18384 KB |
Output is correct |
96 |
Correct |
73 ms |
17356 KB |
Output is correct |
97 |
Correct |
109 ms |
16768 KB |
Output is correct |
98 |
Correct |
70 ms |
16296 KB |
Output is correct |
99 |
Correct |
72 ms |
15936 KB |
Output is correct |
100 |
Correct |
72 ms |
17960 KB |
Output is correct |
101 |
Correct |
72 ms |
16760 KB |
Output is correct |
102 |
Correct |
76 ms |
16392 KB |
Output is correct |
103 |
Correct |
104 ms |
16260 KB |
Output is correct |
104 |
Correct |
55 ms |
16328 KB |
Output is correct |
105 |
Correct |
85 ms |
21344 KB |
Output is correct |
106 |
Correct |
56 ms |
16328 KB |
Output is correct |
107 |
Correct |
77 ms |
16256 KB |
Output is correct |
108 |
Correct |
80 ms |
23636 KB |
Output is correct |
109 |
Correct |
53 ms |
16324 KB |
Output is correct |
110 |
Correct |
83 ms |
23860 KB |
Output is correct |
111 |
Correct |
104 ms |
15664 KB |
Output is correct |