# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1042682 |
2024-08-03T09:39:27 Z |
kukuk |
Power Plant (JOI20_power) |
C++14 |
|
96 ms |
29588 KB |
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned long long int ull;
const ll md = 1e9+7;
const int ukr = 2e5+10;
int read() {
int ketek = 0; bool ne=0;
register char c = getchar();
while(c == ' ' or c =='\n') c =getchar();
if(c=='-'){ne = 1; c = getchar();}
while(c >= '0' and c <='9') { ketek = (ketek<<3)+(ketek<<1)+c-'0'; c = getchar();}
if(ne) ketek*=-1;
return ketek;
}
void print(int x) {
if (x < 0) {putchar('-');x = -x;}
int len = 0, buf[10];
if (x == 0) {putchar('0');return;}
while (x > 0) {buf[len++] = x % 10; x/=10;}
while (len > 0) {putchar('0' + buf[--len]);}
}
void File_Work(){
freopen("test.in","r",stdin);
freopen("test.out","w",stdout);
}
int n, m, a, b, c, d, id;
struct babi{
ll x, y, id;
};
struct babis{
ll x, y;
};
ll gcd(ll a, ll b) {
if (b == 0) return a;
return gcd(b, a % b);
}
ll pgkt(ll rnx, ll rny){
if(rny == 0) return 1;
ll nwrn = pgkt(rnx, rny/2);
if(rny%2){
return (((nwrn*nwrn)%md)*rnx)%md;
}else{
return (nwrn*nwrn)%md;
}
}
vector<vector<int>> adj(ukr);
string s;
ll dp[ukr] = {0}, ans = 0;
void rec(ll rn, ll par){
if(s[rn-1] == '1') dp[rn] = 1;
else dp[rn] = 0;
ll tot = 0, ck = (s[rn-1]-'0');
for(auto i : adj[rn]){
if(i == par) continue;
rec(i, rn);
tot += dp[i];
ans = max(ans, dp[i]+ck);
}
dp[rn] = max(dp[rn], tot-ck);
//cout << dp[rn] << " " << rn << "\n";
ans = max(ans, dp[rn]);
}
void solve(){
cin >> n;
for(int i = 0; i < n-1; i++){
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
cin >> s;
rec(1, 1);
cout << ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t =1;
//cin >> t;
for(int i = 1; i <= t; i++){
//cout << "Case " << i << ": ";
solve();
}
}
Compilation message
power.cpp: In function 'void File_Work()':
power.cpp:25:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | freopen("test.in","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
power.cpp:26:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | freopen("test.out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
5108 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
1 ms |
4956 KB |
Output is correct |
10 |
Correct |
1 ms |
4956 KB |
Output is correct |
11 |
Correct |
1 ms |
4956 KB |
Output is correct |
12 |
Correct |
2 ms |
4956 KB |
Output is correct |
13 |
Correct |
1 ms |
4956 KB |
Output is correct |
14 |
Correct |
1 ms |
4956 KB |
Output is correct |
15 |
Correct |
2 ms |
4956 KB |
Output is correct |
16 |
Correct |
1 ms |
4956 KB |
Output is correct |
17 |
Correct |
1 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
1 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
4956 KB |
Output is correct |
21 |
Correct |
1 ms |
4952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
5108 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
1 ms |
4956 KB |
Output is correct |
10 |
Correct |
1 ms |
4956 KB |
Output is correct |
11 |
Correct |
1 ms |
4956 KB |
Output is correct |
12 |
Correct |
2 ms |
4956 KB |
Output is correct |
13 |
Correct |
1 ms |
4956 KB |
Output is correct |
14 |
Correct |
1 ms |
4956 KB |
Output is correct |
15 |
Correct |
2 ms |
4956 KB |
Output is correct |
16 |
Correct |
1 ms |
4956 KB |
Output is correct |
17 |
Correct |
1 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
1 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
4956 KB |
Output is correct |
21 |
Correct |
1 ms |
4952 KB |
Output is correct |
22 |
Correct |
2 ms |
5184 KB |
Output is correct |
23 |
Correct |
2 ms |
5208 KB |
Output is correct |
24 |
Correct |
1 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 |
2 ms |
5212 KB |
Output is correct |
28 |
Correct |
2 ms |
5212 KB |
Output is correct |
29 |
Correct |
2 ms |
5156 KB |
Output is correct |
30 |
Correct |
2 ms |
5212 KB |
Output is correct |
31 |
Correct |
2 ms |
5212 KB |
Output is correct |
32 |
Correct |
2 ms |
5212 KB |
Output is correct |
33 |
Correct |
2 ms |
5212 KB |
Output is correct |
34 |
Correct |
2 ms |
5212 KB |
Output is correct |
35 |
Correct |
2 ms |
5212 KB |
Output is correct |
36 |
Correct |
2 ms |
5212 KB |
Output is correct |
37 |
Correct |
2 ms |
5244 KB |
Output is correct |
38 |
Correct |
2 ms |
5212 KB |
Output is correct |
39 |
Correct |
2 ms |
5212 KB |
Output is correct |
40 |
Correct |
2 ms |
5212 KB |
Output is correct |
41 |
Correct |
1 ms |
5212 KB |
Output is correct |
42 |
Correct |
2 ms |
5212 KB |
Output is correct |
43 |
Correct |
2 ms |
5208 KB |
Output is correct |
44 |
Correct |
2 ms |
5212 KB |
Output is correct |
45 |
Correct |
2 ms |
5180 KB |
Output is correct |
46 |
Correct |
2 ms |
5188 KB |
Output is correct |
47 |
Correct |
2 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 |
2 ms |
5212 KB |
Output is correct |
51 |
Correct |
2 ms |
5212 KB |
Output is correct |
52 |
Correct |
1 ms |
5212 KB |
Output is correct |
53 |
Correct |
2 ms |
5212 KB |
Output is correct |
54 |
Correct |
2 ms |
5212 KB |
Output is correct |
55 |
Correct |
2 ms |
5208 KB |
Output is correct |
56 |
Correct |
2 ms |
5212 KB |
Output is correct |
57 |
Correct |
2 ms |
5212 KB |
Output is correct |
58 |
Correct |
2 ms |
5184 KB |
Output is correct |
59 |
Correct |
2 ms |
5208 KB |
Output is correct |
60 |
Correct |
1 ms |
5208 KB |
Output is correct |
61 |
Correct |
2 ms |
5212 KB |
Output is correct |
62 |
Correct |
3 ms |
5212 KB |
Output is correct |
63 |
Correct |
2 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 |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
5108 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
1 ms |
4956 KB |
Output is correct |
10 |
Correct |
1 ms |
4956 KB |
Output is correct |
11 |
Correct |
1 ms |
4956 KB |
Output is correct |
12 |
Correct |
2 ms |
4956 KB |
Output is correct |
13 |
Correct |
1 ms |
4956 KB |
Output is correct |
14 |
Correct |
1 ms |
4956 KB |
Output is correct |
15 |
Correct |
2 ms |
4956 KB |
Output is correct |
16 |
Correct |
1 ms |
4956 KB |
Output is correct |
17 |
Correct |
1 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
1 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
4956 KB |
Output is correct |
21 |
Correct |
1 ms |
4952 KB |
Output is correct |
22 |
Correct |
2 ms |
5184 KB |
Output is correct |
23 |
Correct |
2 ms |
5208 KB |
Output is correct |
24 |
Correct |
1 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 |
2 ms |
5212 KB |
Output is correct |
28 |
Correct |
2 ms |
5212 KB |
Output is correct |
29 |
Correct |
2 ms |
5156 KB |
Output is correct |
30 |
Correct |
2 ms |
5212 KB |
Output is correct |
31 |
Correct |
2 ms |
5212 KB |
Output is correct |
32 |
Correct |
2 ms |
5212 KB |
Output is correct |
33 |
Correct |
2 ms |
5212 KB |
Output is correct |
34 |
Correct |
2 ms |
5212 KB |
Output is correct |
35 |
Correct |
2 ms |
5212 KB |
Output is correct |
36 |
Correct |
2 ms |
5212 KB |
Output is correct |
37 |
Correct |
2 ms |
5244 KB |
Output is correct |
38 |
Correct |
2 ms |
5212 KB |
Output is correct |
39 |
Correct |
2 ms |
5212 KB |
Output is correct |
40 |
Correct |
2 ms |
5212 KB |
Output is correct |
41 |
Correct |
1 ms |
5212 KB |
Output is correct |
42 |
Correct |
2 ms |
5212 KB |
Output is correct |
43 |
Correct |
2 ms |
5208 KB |
Output is correct |
44 |
Correct |
2 ms |
5212 KB |
Output is correct |
45 |
Correct |
2 ms |
5180 KB |
Output is correct |
46 |
Correct |
2 ms |
5188 KB |
Output is correct |
47 |
Correct |
2 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 |
2 ms |
5212 KB |
Output is correct |
51 |
Correct |
2 ms |
5212 KB |
Output is correct |
52 |
Correct |
1 ms |
5212 KB |
Output is correct |
53 |
Correct |
2 ms |
5212 KB |
Output is correct |
54 |
Correct |
2 ms |
5212 KB |
Output is correct |
55 |
Correct |
2 ms |
5208 KB |
Output is correct |
56 |
Correct |
2 ms |
5212 KB |
Output is correct |
57 |
Correct |
2 ms |
5212 KB |
Output is correct |
58 |
Correct |
2 ms |
5184 KB |
Output is correct |
59 |
Correct |
2 ms |
5208 KB |
Output is correct |
60 |
Correct |
1 ms |
5208 KB |
Output is correct |
61 |
Correct |
2 ms |
5212 KB |
Output is correct |
62 |
Correct |
3 ms |
5212 KB |
Output is correct |
63 |
Correct |
2 ms |
5212 KB |
Output is correct |
64 |
Correct |
48 ms |
16024 KB |
Output is correct |
65 |
Correct |
52 ms |
16020 KB |
Output is correct |
66 |
Correct |
47 ms |
15892 KB |
Output is correct |
67 |
Correct |
46 ms |
16020 KB |
Output is correct |
68 |
Correct |
82 ms |
16008 KB |
Output is correct |
69 |
Correct |
47 ms |
16124 KB |
Output is correct |
70 |
Correct |
81 ms |
16124 KB |
Output is correct |
71 |
Correct |
48 ms |
16028 KB |
Output is correct |
72 |
Correct |
51 ms |
16024 KB |
Output is correct |
73 |
Correct |
89 ms |
28560 KB |
Output is correct |
74 |
Correct |
96 ms |
28548 KB |
Output is correct |
75 |
Correct |
50 ms |
16028 KB |
Output is correct |
76 |
Correct |
49 ms |
15768 KB |
Output is correct |
77 |
Correct |
53 ms |
16012 KB |
Output is correct |
78 |
Correct |
54 ms |
16028 KB |
Output is correct |
79 |
Correct |
63 ms |
15772 KB |
Output is correct |
80 |
Correct |
77 ms |
15884 KB |
Output is correct |
81 |
Correct |
55 ms |
16332 KB |
Output is correct |
82 |
Correct |
56 ms |
16212 KB |
Output is correct |
83 |
Correct |
55 ms |
21140 KB |
Output is correct |
84 |
Correct |
87 ms |
23180 KB |
Output is correct |
85 |
Correct |
65 ms |
22940 KB |
Output is correct |
86 |
Correct |
50 ms |
17300 KB |
Output is correct |
87 |
Correct |
83 ms |
16784 KB |
Output is correct |
88 |
Correct |
56 ms |
17100 KB |
Output is correct |
89 |
Correct |
44 ms |
17312 KB |
Output is correct |
90 |
Correct |
63 ms |
17136 KB |
Output is correct |
91 |
Correct |
46 ms |
17268 KB |
Output is correct |
92 |
Correct |
50 ms |
17592 KB |
Output is correct |
93 |
Correct |
44 ms |
19836 KB |
Output is correct |
94 |
Correct |
44 ms |
21708 KB |
Output is correct |
95 |
Correct |
53 ms |
20340 KB |
Output is correct |
96 |
Correct |
46 ms |
18488 KB |
Output is correct |
97 |
Correct |
47 ms |
17128 KB |
Output is correct |
98 |
Correct |
46 ms |
16576 KB |
Output is correct |
99 |
Correct |
43 ms |
16272 KB |
Output is correct |
100 |
Correct |
47 ms |
19528 KB |
Output is correct |
101 |
Correct |
56 ms |
17420 KB |
Output is correct |
102 |
Correct |
52 ms |
16736 KB |
Output is correct |
103 |
Correct |
45 ms |
16572 KB |
Output is correct |
104 |
Correct |
33 ms |
16840 KB |
Output is correct |
105 |
Correct |
55 ms |
25492 KB |
Output is correct |
106 |
Correct |
37 ms |
16748 KB |
Output is correct |
107 |
Correct |
33 ms |
16848 KB |
Output is correct |
108 |
Correct |
57 ms |
29408 KB |
Output is correct |
109 |
Correct |
32 ms |
16848 KB |
Output is correct |
110 |
Correct |
55 ms |
29588 KB |
Output is correct |
111 |
Correct |
41 ms |
15776 KB |
Output is correct |