# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
626783 |
2022-08-11T18:55:54 Z |
codr0 |
Power Plant (JOI20_power) |
C++14 |
|
131 ms |
30488 KB |
// Code by Parsa Eslami
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORR(i,a,b) for(int i=a;i>=b;i--)
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define bit(i,j) ((j>>i)&1)
#define pb push_back
#define lc 2*id
#define rc 2*id+1
#define dmid int mid=(r+l)/2
#define err(x) cerr<#x<<" : "<<x<<'\n'
using namespace std;
const int N=2e5+4;
vector<int> adj[N];
int gen[N];
int dp[N][2];
int in(){
int x; cin>>x; return x;
}
void dfs(int v,int p){
int sg1=0,mx1=0,mx0=0;
for(int u:adj[v]) if(u!=p){
dfs(u,v);
sg1+=dp[u][1];
maxm(mx1,dp[u][1]);
maxm(mx0,dp[u][0]);
}
maxm(dp[v][1],gen[v]);
maxm(dp[v][1],sg1-gen[v]);
maxm(dp[v][0],mx0);
maxm(dp[v][0],mx1+gen[v]);
maxm(dp[v][0],sg1-gen[v]);
}
int32_t main(){
iostream::sync_with_stdio(0); cin.tie(0);
int n=in();
FOR(i,1,n-1){
int u=in(),v=in();
adj[u].pb(v);
adj[v].pb(u);
}
string s; cin>>s;
FOR(i,0,n-1) gen[i+1]=s[i]-'0';
dfs(1,1);
cout<<dp[1][0]<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
2 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
5036 KB |
Output is correct |
19 |
Correct |
4 ms |
4948 KB |
Output is correct |
20 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
2 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
5036 KB |
Output is correct |
19 |
Correct |
4 ms |
4948 KB |
Output is correct |
20 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4936 KB |
Output is correct |
22 |
Correct |
3 ms |
5076 KB |
Output is correct |
23 |
Correct |
3 ms |
5076 KB |
Output is correct |
24 |
Correct |
3 ms |
5076 KB |
Output is correct |
25 |
Correct |
3 ms |
5076 KB |
Output is correct |
26 |
Correct |
3 ms |
5076 KB |
Output is correct |
27 |
Correct |
3 ms |
5076 KB |
Output is correct |
28 |
Correct |
3 ms |
5076 KB |
Output is correct |
29 |
Correct |
3 ms |
5204 KB |
Output is correct |
30 |
Correct |
3 ms |
5204 KB |
Output is correct |
31 |
Correct |
3 ms |
5076 KB |
Output is correct |
32 |
Correct |
3 ms |
5076 KB |
Output is correct |
33 |
Correct |
3 ms |
5076 KB |
Output is correct |
34 |
Correct |
3 ms |
5076 KB |
Output is correct |
35 |
Correct |
3 ms |
5076 KB |
Output is correct |
36 |
Correct |
3 ms |
5076 KB |
Output is correct |
37 |
Correct |
3 ms |
5076 KB |
Output is correct |
38 |
Correct |
3 ms |
5076 KB |
Output is correct |
39 |
Correct |
3 ms |
5076 KB |
Output is correct |
40 |
Correct |
4 ms |
5072 KB |
Output is correct |
41 |
Correct |
3 ms |
5076 KB |
Output is correct |
42 |
Correct |
3 ms |
5204 KB |
Output is correct |
43 |
Correct |
3 ms |
5028 KB |
Output is correct |
44 |
Correct |
3 ms |
5076 KB |
Output is correct |
45 |
Correct |
3 ms |
5076 KB |
Output is correct |
46 |
Correct |
4 ms |
5204 KB |
Output is correct |
47 |
Correct |
3 ms |
5076 KB |
Output is correct |
48 |
Correct |
3 ms |
5204 KB |
Output is correct |
49 |
Correct |
3 ms |
5204 KB |
Output is correct |
50 |
Correct |
3 ms |
5076 KB |
Output is correct |
51 |
Correct |
3 ms |
5076 KB |
Output is correct |
52 |
Correct |
3 ms |
5076 KB |
Output is correct |
53 |
Correct |
3 ms |
5076 KB |
Output is correct |
54 |
Correct |
3 ms |
5076 KB |
Output is correct |
55 |
Correct |
3 ms |
5076 KB |
Output is correct |
56 |
Correct |
3 ms |
5076 KB |
Output is correct |
57 |
Correct |
3 ms |
5204 KB |
Output is correct |
58 |
Correct |
3 ms |
5076 KB |
Output is correct |
59 |
Correct |
3 ms |
5076 KB |
Output is correct |
60 |
Correct |
3 ms |
5204 KB |
Output is correct |
61 |
Correct |
3 ms |
5076 KB |
Output is correct |
62 |
Correct |
3 ms |
5204 KB |
Output is correct |
63 |
Correct |
3 ms |
5076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
2 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
5036 KB |
Output is correct |
19 |
Correct |
4 ms |
4948 KB |
Output is correct |
20 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4936 KB |
Output is correct |
22 |
Correct |
3 ms |
5076 KB |
Output is correct |
23 |
Correct |
3 ms |
5076 KB |
Output is correct |
24 |
Correct |
3 ms |
5076 KB |
Output is correct |
25 |
Correct |
3 ms |
5076 KB |
Output is correct |
26 |
Correct |
3 ms |
5076 KB |
Output is correct |
27 |
Correct |
3 ms |
5076 KB |
Output is correct |
28 |
Correct |
3 ms |
5076 KB |
Output is correct |
29 |
Correct |
3 ms |
5204 KB |
Output is correct |
30 |
Correct |
3 ms |
5204 KB |
Output is correct |
31 |
Correct |
3 ms |
5076 KB |
Output is correct |
32 |
Correct |
3 ms |
5076 KB |
Output is correct |
33 |
Correct |
3 ms |
5076 KB |
Output is correct |
34 |
Correct |
3 ms |
5076 KB |
Output is correct |
35 |
Correct |
3 ms |
5076 KB |
Output is correct |
36 |
Correct |
3 ms |
5076 KB |
Output is correct |
37 |
Correct |
3 ms |
5076 KB |
Output is correct |
38 |
Correct |
3 ms |
5076 KB |
Output is correct |
39 |
Correct |
3 ms |
5076 KB |
Output is correct |
40 |
Correct |
4 ms |
5072 KB |
Output is correct |
41 |
Correct |
3 ms |
5076 KB |
Output is correct |
42 |
Correct |
3 ms |
5204 KB |
Output is correct |
43 |
Correct |
3 ms |
5028 KB |
Output is correct |
44 |
Correct |
3 ms |
5076 KB |
Output is correct |
45 |
Correct |
3 ms |
5076 KB |
Output is correct |
46 |
Correct |
4 ms |
5204 KB |
Output is correct |
47 |
Correct |
3 ms |
5076 KB |
Output is correct |
48 |
Correct |
3 ms |
5204 KB |
Output is correct |
49 |
Correct |
3 ms |
5204 KB |
Output is correct |
50 |
Correct |
3 ms |
5076 KB |
Output is correct |
51 |
Correct |
3 ms |
5076 KB |
Output is correct |
52 |
Correct |
3 ms |
5076 KB |
Output is correct |
53 |
Correct |
3 ms |
5076 KB |
Output is correct |
54 |
Correct |
3 ms |
5076 KB |
Output is correct |
55 |
Correct |
3 ms |
5076 KB |
Output is correct |
56 |
Correct |
3 ms |
5076 KB |
Output is correct |
57 |
Correct |
3 ms |
5204 KB |
Output is correct |
58 |
Correct |
3 ms |
5076 KB |
Output is correct |
59 |
Correct |
3 ms |
5076 KB |
Output is correct |
60 |
Correct |
3 ms |
5204 KB |
Output is correct |
61 |
Correct |
3 ms |
5076 KB |
Output is correct |
62 |
Correct |
3 ms |
5204 KB |
Output is correct |
63 |
Correct |
3 ms |
5076 KB |
Output is correct |
64 |
Correct |
115 ms |
14004 KB |
Output is correct |
65 |
Correct |
113 ms |
14028 KB |
Output is correct |
66 |
Correct |
107 ms |
14052 KB |
Output is correct |
67 |
Correct |
109 ms |
14004 KB |
Output is correct |
68 |
Correct |
115 ms |
14084 KB |
Output is correct |
69 |
Correct |
115 ms |
13976 KB |
Output is correct |
70 |
Correct |
109 ms |
14040 KB |
Output is correct |
71 |
Correct |
108 ms |
13964 KB |
Output is correct |
72 |
Correct |
109 ms |
14040 KB |
Output is correct |
73 |
Correct |
129 ms |
29216 KB |
Output is correct |
74 |
Correct |
131 ms |
29028 KB |
Output is correct |
75 |
Correct |
109 ms |
13896 KB |
Output is correct |
76 |
Correct |
125 ms |
13828 KB |
Output is correct |
77 |
Correct |
120 ms |
13872 KB |
Output is correct |
78 |
Correct |
106 ms |
13888 KB |
Output is correct |
79 |
Correct |
109 ms |
13840 KB |
Output is correct |
80 |
Correct |
112 ms |
13852 KB |
Output is correct |
81 |
Correct |
88 ms |
14428 KB |
Output is correct |
82 |
Correct |
100 ms |
14060 KB |
Output is correct |
83 |
Correct |
117 ms |
20076 KB |
Output is correct |
84 |
Correct |
120 ms |
22684 KB |
Output is correct |
85 |
Correct |
116 ms |
22308 KB |
Output is correct |
86 |
Correct |
117 ms |
15648 KB |
Output is correct |
87 |
Correct |
113 ms |
14952 KB |
Output is correct |
88 |
Correct |
104 ms |
15400 KB |
Output is correct |
89 |
Correct |
106 ms |
15416 KB |
Output is correct |
90 |
Correct |
107 ms |
15128 KB |
Output is correct |
91 |
Correct |
104 ms |
15392 KB |
Output is correct |
92 |
Correct |
105 ms |
15808 KB |
Output is correct |
93 |
Correct |
100 ms |
18844 KB |
Output is correct |
94 |
Correct |
103 ms |
20976 KB |
Output is correct |
95 |
Correct |
97 ms |
19224 KB |
Output is correct |
96 |
Correct |
103 ms |
16960 KB |
Output is correct |
97 |
Correct |
103 ms |
15184 KB |
Output is correct |
98 |
Correct |
109 ms |
14516 KB |
Output is correct |
99 |
Correct |
103 ms |
14404 KB |
Output is correct |
100 |
Correct |
100 ms |
18168 KB |
Output is correct |
101 |
Correct |
105 ms |
15704 KB |
Output is correct |
102 |
Correct |
98 ms |
14816 KB |
Output is correct |
103 |
Correct |
115 ms |
14536 KB |
Output is correct |
104 |
Correct |
62 ms |
14688 KB |
Output is correct |
105 |
Correct |
121 ms |
25352 KB |
Output is correct |
106 |
Correct |
61 ms |
14880 KB |
Output is correct |
107 |
Correct |
61 ms |
14788 KB |
Output is correct |
108 |
Correct |
129 ms |
29996 KB |
Output is correct |
109 |
Correct |
66 ms |
14800 KB |
Output is correct |
110 |
Correct |
128 ms |
30488 KB |
Output is correct |
111 |
Correct |
110 ms |
13884 KB |
Output is correct |