# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1065789 |
2024-08-19T11:46:56 Z |
Malix |
Power Plant (JOI20_power) |
C++14 |
|
281 ms |
29264 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pi;
typedef vector<pi> pii;
typedef tuple<int,int,int> tii;
typedef vector<ll> li;
typedef vector<li> lii;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define LSOne(s) ((s)&(-s))
ll INF=1000000000000000010;
int inf=1e9+10;
ll M=1e9+7;
int n;
vii a;
vi p,dp;
int ans=0;
void dfs(int x){
int k=0;
int c=0;
for(auto u:a[x]){
if(p[x]==u)continue;
p[u]=x;
dfs(u);
k+=dp[u];
c=max(c,dp[u]);
}
if(dp[x]){
if(x==0&&a[x].size()==1){
ans=max(ans,dp[x]+k);
dp[x]=max(dp[x],k-1);
return;
}
else if(x!=0&&a[x].size()==2){
ans=max(ans,dp[x]+k);
dp[x]=max(dp[x],k-1);
return;
}
ans=max(ans,c+1);
dp[x]=max(dp[x],k-1);
return;
}
dp[x]=k;
}
int main() {
cin>>n;
a.resize(n);p.resize(n,-1);dp.resize(n,0);
REP(i,0,n-1){
int x,y;cin>>x>>y;
x--;y--;
a[x].PB(y);
a[y].PB(x);
}
REP(i,0,n){
char x;cin>>x;
if(x-'0'==1)dp[i]=1;
}
dfs(0);
ans=max(ans,*max_element(dp.begin(),dp.end()));
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
2 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 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 |
568 KB |
Output is correct |
42 |
Correct |
1 ms |
604 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
1 ms |
600 KB |
Output is correct |
45 |
Correct |
2 ms |
604 KB |
Output is correct |
46 |
Correct |
1 ms |
348 KB |
Output is correct |
47 |
Correct |
1 ms |
348 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 |
604 KB |
Output is correct |
55 |
Correct |
1 ms |
600 KB |
Output is correct |
56 |
Correct |
1 ms |
348 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 |
348 KB |
Output is correct |
60 |
Correct |
1 ms |
448 KB |
Output is correct |
61 |
Correct |
1 ms |
348 KB |
Output is correct |
62 |
Correct |
1 ms |
604 KB |
Output is correct |
63 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
2 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 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 |
568 KB |
Output is correct |
42 |
Correct |
1 ms |
604 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
1 ms |
600 KB |
Output is correct |
45 |
Correct |
2 ms |
604 KB |
Output is correct |
46 |
Correct |
1 ms |
348 KB |
Output is correct |
47 |
Correct |
1 ms |
348 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 |
604 KB |
Output is correct |
55 |
Correct |
1 ms |
600 KB |
Output is correct |
56 |
Correct |
1 ms |
348 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 |
348 KB |
Output is correct |
60 |
Correct |
1 ms |
448 KB |
Output is correct |
61 |
Correct |
1 ms |
348 KB |
Output is correct |
62 |
Correct |
1 ms |
604 KB |
Output is correct |
63 |
Correct |
1 ms |
604 KB |
Output is correct |
64 |
Correct |
120 ms |
15704 KB |
Output is correct |
65 |
Correct |
100 ms |
15700 KB |
Output is correct |
66 |
Correct |
106 ms |
15696 KB |
Output is correct |
67 |
Correct |
109 ms |
15544 KB |
Output is correct |
68 |
Correct |
105 ms |
15696 KB |
Output is correct |
69 |
Correct |
124 ms |
15596 KB |
Output is correct |
70 |
Correct |
116 ms |
15700 KB |
Output is correct |
71 |
Correct |
104 ms |
15552 KB |
Output is correct |
72 |
Correct |
102 ms |
15700 KB |
Output is correct |
73 |
Correct |
123 ms |
28500 KB |
Output is correct |
74 |
Correct |
113 ms |
28240 KB |
Output is correct |
75 |
Correct |
108 ms |
15576 KB |
Output is correct |
76 |
Correct |
105 ms |
15440 KB |
Output is correct |
77 |
Correct |
125 ms |
15440 KB |
Output is correct |
78 |
Correct |
103 ms |
15440 KB |
Output is correct |
79 |
Correct |
105 ms |
15440 KB |
Output is correct |
80 |
Correct |
127 ms |
15444 KB |
Output is correct |
81 |
Correct |
128 ms |
15792 KB |
Output is correct |
82 |
Correct |
99 ms |
15824 KB |
Output is correct |
83 |
Correct |
112 ms |
20820 KB |
Output is correct |
84 |
Correct |
112 ms |
22784 KB |
Output is correct |
85 |
Correct |
122 ms |
22608 KB |
Output is correct |
86 |
Correct |
110 ms |
16980 KB |
Output is correct |
87 |
Correct |
102 ms |
16504 KB |
Output is correct |
88 |
Correct |
113 ms |
16976 KB |
Output is correct |
89 |
Correct |
114 ms |
16980 KB |
Output is correct |
90 |
Correct |
281 ms |
16644 KB |
Output is correct |
91 |
Correct |
110 ms |
16980 KB |
Output is correct |
92 |
Correct |
114 ms |
17336 KB |
Output is correct |
93 |
Correct |
100 ms |
19664 KB |
Output is correct |
94 |
Correct |
105 ms |
21192 KB |
Output is correct |
95 |
Correct |
100 ms |
19916 KB |
Output is correct |
96 |
Correct |
102 ms |
18260 KB |
Output is correct |
97 |
Correct |
104 ms |
16720 KB |
Output is correct |
98 |
Correct |
104 ms |
16188 KB |
Output is correct |
99 |
Correct |
103 ms |
15952 KB |
Output is correct |
100 |
Correct |
103 ms |
19184 KB |
Output is correct |
101 |
Correct |
117 ms |
17052 KB |
Output is correct |
102 |
Correct |
99 ms |
16464 KB |
Output is correct |
103 |
Correct |
101 ms |
16208 KB |
Output is correct |
104 |
Correct |
87 ms |
16316 KB |
Output is correct |
105 |
Correct |
105 ms |
25032 KB |
Output is correct |
106 |
Correct |
115 ms |
16324 KB |
Output is correct |
107 |
Correct |
97 ms |
16164 KB |
Output is correct |
108 |
Correct |
114 ms |
29100 KB |
Output is correct |
109 |
Correct |
91 ms |
16348 KB |
Output is correct |
110 |
Correct |
124 ms |
29264 KB |
Output is correct |
111 |
Correct |
99 ms |
15440 KB |
Output is correct |