# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
849773 |
2023-09-15T10:32:21 Z |
Abito |
Power Plant (JOI20_power) |
C++17 |
|
183 ms |
26704 KB |
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
#define y1 YONE
typedef unsigned long long ull;
using namespace std;
const int N=2e5+5;
int n,dp[N],ans;
vector<int> adj[N];
bool a[N];
int rec(int node,int p){
//int s=bool(p);
dp[node]=0;
for (auto u:adj[node]) if (u!=p) dp[node]+=rec(u,node);
if (adj[node].size()<=1) dp[node]+=a[node];
else dp[node]-=a[node];
return dp[node]=max(dp[node],(int)a[node]);
}
void dfs(int node,int p){
if (p) dp[p]=max(dp[p]-dp[node],(int)a[p]);
dp[node]=max(dp[node]+dp[p],(int)a[node]);
ans=max(ans,dp[node]);
for (auto u:adj[node]) if (u!=p) dfs(u,node);
return;
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin>>n;
for (int i=1;i<n;i++){
int x,y;cin>>x>>y;
adj[x].pb(y);adj[y].pb(x);
}for (int i=1;i<=n;i++){char c;cin>>c;a[i]=c-'0';}
rec(1,0);
dfs(1,0);
cout<<ans<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
2 ms |
6488 KB |
Output is correct |
4 |
Correct |
2 ms |
6488 KB |
Output is correct |
5 |
Correct |
1 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Correct |
2 ms |
6488 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
2 ms |
6488 KB |
Output is correct |
10 |
Correct |
1 ms |
6488 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6488 KB |
Output is correct |
14 |
Correct |
1 ms |
6488 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6488 KB |
Output is correct |
17 |
Correct |
2 ms |
6488 KB |
Output is correct |
18 |
Correct |
1 ms |
6488 KB |
Output is correct |
19 |
Correct |
1 ms |
6488 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
2 ms |
6488 KB |
Output is correct |
4 |
Correct |
2 ms |
6488 KB |
Output is correct |
5 |
Correct |
1 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Correct |
2 ms |
6488 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
2 ms |
6488 KB |
Output is correct |
10 |
Correct |
1 ms |
6488 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6488 KB |
Output is correct |
14 |
Correct |
1 ms |
6488 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6488 KB |
Output is correct |
17 |
Correct |
2 ms |
6488 KB |
Output is correct |
18 |
Correct |
1 ms |
6488 KB |
Output is correct |
19 |
Correct |
1 ms |
6488 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6488 KB |
Output is correct |
22 |
Correct |
2 ms |
6488 KB |
Output is correct |
23 |
Correct |
2 ms |
6488 KB |
Output is correct |
24 |
Correct |
2 ms |
6488 KB |
Output is correct |
25 |
Correct |
2 ms |
6492 KB |
Output is correct |
26 |
Correct |
2 ms |
6492 KB |
Output is correct |
27 |
Correct |
2 ms |
6496 KB |
Output is correct |
28 |
Correct |
2 ms |
6692 KB |
Output is correct |
29 |
Correct |
2 ms |
6744 KB |
Output is correct |
30 |
Correct |
2 ms |
6744 KB |
Output is correct |
31 |
Correct |
2 ms |
6488 KB |
Output is correct |
32 |
Correct |
2 ms |
6488 KB |
Output is correct |
33 |
Correct |
2 ms |
6488 KB |
Output is correct |
34 |
Correct |
2 ms |
6488 KB |
Output is correct |
35 |
Correct |
2 ms |
6488 KB |
Output is correct |
36 |
Correct |
2 ms |
6488 KB |
Output is correct |
37 |
Correct |
2 ms |
6488 KB |
Output is correct |
38 |
Correct |
2 ms |
6492 KB |
Output is correct |
39 |
Correct |
2 ms |
6492 KB |
Output is correct |
40 |
Correct |
2 ms |
6488 KB |
Output is correct |
41 |
Correct |
2 ms |
6488 KB |
Output is correct |
42 |
Correct |
2 ms |
6488 KB |
Output is correct |
43 |
Correct |
2 ms |
6488 KB |
Output is correct |
44 |
Correct |
2 ms |
6488 KB |
Output is correct |
45 |
Correct |
2 ms |
6492 KB |
Output is correct |
46 |
Correct |
2 ms |
6488 KB |
Output is correct |
47 |
Correct |
2 ms |
6488 KB |
Output is correct |
48 |
Correct |
2 ms |
6488 KB |
Output is correct |
49 |
Correct |
2 ms |
6744 KB |
Output is correct |
50 |
Correct |
2 ms |
6592 KB |
Output is correct |
51 |
Correct |
2 ms |
6488 KB |
Output is correct |
52 |
Correct |
2 ms |
6492 KB |
Output is correct |
53 |
Correct |
2 ms |
6488 KB |
Output is correct |
54 |
Correct |
2 ms |
6488 KB |
Output is correct |
55 |
Correct |
2 ms |
6488 KB |
Output is correct |
56 |
Correct |
2 ms |
6488 KB |
Output is correct |
57 |
Correct |
2 ms |
6744 KB |
Output is correct |
58 |
Correct |
2 ms |
6488 KB |
Output is correct |
59 |
Correct |
2 ms |
6488 KB |
Output is correct |
60 |
Correct |
2 ms |
6744 KB |
Output is correct |
61 |
Correct |
2 ms |
6488 KB |
Output is correct |
62 |
Correct |
2 ms |
6744 KB |
Output is correct |
63 |
Correct |
2 ms |
6496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
2 ms |
6488 KB |
Output is correct |
4 |
Correct |
2 ms |
6488 KB |
Output is correct |
5 |
Correct |
1 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Correct |
2 ms |
6488 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
2 ms |
6488 KB |
Output is correct |
10 |
Correct |
1 ms |
6488 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6488 KB |
Output is correct |
14 |
Correct |
1 ms |
6488 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6488 KB |
Output is correct |
17 |
Correct |
2 ms |
6488 KB |
Output is correct |
18 |
Correct |
1 ms |
6488 KB |
Output is correct |
19 |
Correct |
1 ms |
6488 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6488 KB |
Output is correct |
22 |
Correct |
2 ms |
6488 KB |
Output is correct |
23 |
Correct |
2 ms |
6488 KB |
Output is correct |
24 |
Correct |
2 ms |
6488 KB |
Output is correct |
25 |
Correct |
2 ms |
6492 KB |
Output is correct |
26 |
Correct |
2 ms |
6492 KB |
Output is correct |
27 |
Correct |
2 ms |
6496 KB |
Output is correct |
28 |
Correct |
2 ms |
6692 KB |
Output is correct |
29 |
Correct |
2 ms |
6744 KB |
Output is correct |
30 |
Correct |
2 ms |
6744 KB |
Output is correct |
31 |
Correct |
2 ms |
6488 KB |
Output is correct |
32 |
Correct |
2 ms |
6488 KB |
Output is correct |
33 |
Correct |
2 ms |
6488 KB |
Output is correct |
34 |
Correct |
2 ms |
6488 KB |
Output is correct |
35 |
Correct |
2 ms |
6488 KB |
Output is correct |
36 |
Correct |
2 ms |
6488 KB |
Output is correct |
37 |
Correct |
2 ms |
6488 KB |
Output is correct |
38 |
Correct |
2 ms |
6492 KB |
Output is correct |
39 |
Correct |
2 ms |
6492 KB |
Output is correct |
40 |
Correct |
2 ms |
6488 KB |
Output is correct |
41 |
Correct |
2 ms |
6488 KB |
Output is correct |
42 |
Correct |
2 ms |
6488 KB |
Output is correct |
43 |
Correct |
2 ms |
6488 KB |
Output is correct |
44 |
Correct |
2 ms |
6488 KB |
Output is correct |
45 |
Correct |
2 ms |
6492 KB |
Output is correct |
46 |
Correct |
2 ms |
6488 KB |
Output is correct |
47 |
Correct |
2 ms |
6488 KB |
Output is correct |
48 |
Correct |
2 ms |
6488 KB |
Output is correct |
49 |
Correct |
2 ms |
6744 KB |
Output is correct |
50 |
Correct |
2 ms |
6592 KB |
Output is correct |
51 |
Correct |
2 ms |
6488 KB |
Output is correct |
52 |
Correct |
2 ms |
6492 KB |
Output is correct |
53 |
Correct |
2 ms |
6488 KB |
Output is correct |
54 |
Correct |
2 ms |
6488 KB |
Output is correct |
55 |
Correct |
2 ms |
6488 KB |
Output is correct |
56 |
Correct |
2 ms |
6488 KB |
Output is correct |
57 |
Correct |
2 ms |
6744 KB |
Output is correct |
58 |
Correct |
2 ms |
6488 KB |
Output is correct |
59 |
Correct |
2 ms |
6488 KB |
Output is correct |
60 |
Correct |
2 ms |
6744 KB |
Output is correct |
61 |
Correct |
2 ms |
6488 KB |
Output is correct |
62 |
Correct |
2 ms |
6744 KB |
Output is correct |
63 |
Correct |
2 ms |
6496 KB |
Output is correct |
64 |
Correct |
124 ms |
16956 KB |
Output is correct |
65 |
Correct |
103 ms |
16720 KB |
Output is correct |
66 |
Correct |
84 ms |
16976 KB |
Output is correct |
67 |
Correct |
75 ms |
16720 KB |
Output is correct |
68 |
Correct |
103 ms |
16748 KB |
Output is correct |
69 |
Correct |
75 ms |
16972 KB |
Output is correct |
70 |
Correct |
88 ms |
16736 KB |
Output is correct |
71 |
Correct |
79 ms |
16968 KB |
Output is correct |
72 |
Correct |
80 ms |
16720 KB |
Output is correct |
73 |
Correct |
113 ms |
26064 KB |
Output is correct |
74 |
Correct |
103 ms |
25892 KB |
Output is correct |
75 |
Correct |
79 ms |
18208 KB |
Output is correct |
76 |
Correct |
120 ms |
18132 KB |
Output is correct |
77 |
Correct |
87 ms |
16724 KB |
Output is correct |
78 |
Correct |
86 ms |
16724 KB |
Output is correct |
79 |
Correct |
122 ms |
16976 KB |
Output is correct |
80 |
Correct |
75 ms |
16952 KB |
Output is correct |
81 |
Correct |
64 ms |
16832 KB |
Output is correct |
82 |
Correct |
68 ms |
16812 KB |
Output is correct |
83 |
Correct |
183 ms |
20900 KB |
Output is correct |
84 |
Correct |
128 ms |
22568 KB |
Output is correct |
85 |
Correct |
95 ms |
22256 KB |
Output is correct |
86 |
Correct |
83 ms |
18256 KB |
Output is correct |
87 |
Correct |
94 ms |
17576 KB |
Output is correct |
88 |
Correct |
83 ms |
17488 KB |
Output is correct |
89 |
Correct |
116 ms |
17680 KB |
Output is correct |
90 |
Correct |
103 ms |
17688 KB |
Output is correct |
91 |
Correct |
73 ms |
17572 KB |
Output is correct |
92 |
Correct |
122 ms |
18000 KB |
Output is correct |
93 |
Correct |
87 ms |
19400 KB |
Output is correct |
94 |
Correct |
86 ms |
20932 KB |
Output is correct |
95 |
Correct |
79 ms |
19956 KB |
Output is correct |
96 |
Correct |
83 ms |
18512 KB |
Output is correct |
97 |
Correct |
119 ms |
17376 KB |
Output is correct |
98 |
Correct |
97 ms |
16976 KB |
Output is correct |
99 |
Correct |
89 ms |
16976 KB |
Output is correct |
100 |
Correct |
80 ms |
19280 KB |
Output is correct |
101 |
Correct |
74 ms |
17648 KB |
Output is correct |
102 |
Correct |
101 ms |
17080 KB |
Output is correct |
103 |
Correct |
76 ms |
17232 KB |
Output is correct |
104 |
Correct |
60 ms |
17396 KB |
Output is correct |
105 |
Correct |
98 ms |
23376 KB |
Output is correct |
106 |
Correct |
50 ms |
17344 KB |
Output is correct |
107 |
Correct |
67 ms |
17324 KB |
Output is correct |
108 |
Correct |
130 ms |
26704 KB |
Output is correct |
109 |
Correct |
46 ms |
17340 KB |
Output is correct |
110 |
Correct |
101 ms |
26704 KB |
Output is correct |
111 |
Correct |
80 ms |
16724 KB |
Output is correct |