# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
332632 |
2020-12-03T01:53:44 Z |
YJU |
Power Plant (JOI20_power) |
C++14 |
|
1500 ms |
34988 KB |
#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=4e5+5;
const ll K=350;
const ld pi=acos(-1);
const ll INF=(1LL<<60);
#define SQ(i) ((i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()
ll n,x,y,h[N],dp[N],ans,col[N],sum;
vector<ll> v[N];
string s;
void DFS(ll nd,ll pa){
dp[nd]=0;
for(auto i:v[nd]){
if(i==pa)continue;
DFS(i,nd);
dp[nd]+=dp[i];
}
dp[nd]=max(dp[nd]-col[nd],col[nd]);
return ;
}
void move(ll rt,ll to){
dp[rt]=0;
for(auto i:v[rt]){
if(i==to)continue;
dp[rt]+=dp[i];
}
dp[rt]=max(dp[rt]-col[rt],col[rt]);
dp[to]=0;
for(auto i:v[to]){
dp[to]+=dp[i];
}
dp[to]=max(dp[to]-col[to],col[to]);
}
void reroot(ll nd,ll pa){
ans=max(ans,dp[nd]);
for(auto i:v[nd]){
if(i==pa)continue;
move(nd,i);
reroot(i,nd);
move(i,nd);
}
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n;
REP(i,n-1)cin>>x>>y,v[x].pb(y),v[y].pb(x);
cin>>s;
REP(i,n)if(s[i]=='1')col[i+1]=1,++sum;
if(sum>=2)ans=2;else ans=sum;
DFS(1,0);
reroot(1,0);
cout<<ans<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9708 KB |
Output is correct |
2 |
Correct |
7 ms |
9708 KB |
Output is correct |
3 |
Correct |
7 ms |
9708 KB |
Output is correct |
4 |
Correct |
7 ms |
9708 KB |
Output is correct |
5 |
Correct |
7 ms |
9708 KB |
Output is correct |
6 |
Correct |
7 ms |
9708 KB |
Output is correct |
7 |
Correct |
7 ms |
9708 KB |
Output is correct |
8 |
Correct |
7 ms |
9708 KB |
Output is correct |
9 |
Correct |
7 ms |
9708 KB |
Output is correct |
10 |
Correct |
7 ms |
9728 KB |
Output is correct |
11 |
Correct |
7 ms |
9708 KB |
Output is correct |
12 |
Correct |
7 ms |
9708 KB |
Output is correct |
13 |
Correct |
7 ms |
9708 KB |
Output is correct |
14 |
Correct |
7 ms |
9708 KB |
Output is correct |
15 |
Correct |
7 ms |
9708 KB |
Output is correct |
16 |
Correct |
7 ms |
9728 KB |
Output is correct |
17 |
Correct |
7 ms |
9708 KB |
Output is correct |
18 |
Correct |
7 ms |
9708 KB |
Output is correct |
19 |
Correct |
7 ms |
9708 KB |
Output is correct |
20 |
Correct |
7 ms |
9708 KB |
Output is correct |
21 |
Correct |
7 ms |
9708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9708 KB |
Output is correct |
2 |
Correct |
7 ms |
9708 KB |
Output is correct |
3 |
Correct |
7 ms |
9708 KB |
Output is correct |
4 |
Correct |
7 ms |
9708 KB |
Output is correct |
5 |
Correct |
7 ms |
9708 KB |
Output is correct |
6 |
Correct |
7 ms |
9708 KB |
Output is correct |
7 |
Correct |
7 ms |
9708 KB |
Output is correct |
8 |
Correct |
7 ms |
9708 KB |
Output is correct |
9 |
Correct |
7 ms |
9708 KB |
Output is correct |
10 |
Correct |
7 ms |
9728 KB |
Output is correct |
11 |
Correct |
7 ms |
9708 KB |
Output is correct |
12 |
Correct |
7 ms |
9708 KB |
Output is correct |
13 |
Correct |
7 ms |
9708 KB |
Output is correct |
14 |
Correct |
7 ms |
9708 KB |
Output is correct |
15 |
Correct |
7 ms |
9708 KB |
Output is correct |
16 |
Correct |
7 ms |
9728 KB |
Output is correct |
17 |
Correct |
7 ms |
9708 KB |
Output is correct |
18 |
Correct |
7 ms |
9708 KB |
Output is correct |
19 |
Correct |
7 ms |
9708 KB |
Output is correct |
20 |
Correct |
7 ms |
9708 KB |
Output is correct |
21 |
Correct |
7 ms |
9708 KB |
Output is correct |
22 |
Correct |
8 ms |
9836 KB |
Output is correct |
23 |
Correct |
8 ms |
9836 KB |
Output is correct |
24 |
Correct |
8 ms |
9836 KB |
Output is correct |
25 |
Correct |
8 ms |
9836 KB |
Output is correct |
26 |
Correct |
8 ms |
9836 KB |
Output is correct |
27 |
Correct |
8 ms |
9836 KB |
Output is correct |
28 |
Correct |
8 ms |
9836 KB |
Output is correct |
29 |
Correct |
8 ms |
9964 KB |
Output is correct |
30 |
Correct |
8 ms |
9964 KB |
Output is correct |
31 |
Correct |
8 ms |
9836 KB |
Output is correct |
32 |
Correct |
8 ms |
9836 KB |
Output is correct |
33 |
Correct |
9 ms |
9836 KB |
Output is correct |
34 |
Correct |
8 ms |
9856 KB |
Output is correct |
35 |
Correct |
8 ms |
9836 KB |
Output is correct |
36 |
Correct |
7 ms |
9836 KB |
Output is correct |
37 |
Correct |
9 ms |
9836 KB |
Output is correct |
38 |
Correct |
8 ms |
9836 KB |
Output is correct |
39 |
Correct |
8 ms |
9964 KB |
Output is correct |
40 |
Correct |
8 ms |
9836 KB |
Output is correct |
41 |
Correct |
8 ms |
9964 KB |
Output is correct |
42 |
Correct |
8 ms |
9836 KB |
Output is correct |
43 |
Correct |
8 ms |
9836 KB |
Output is correct |
44 |
Correct |
8 ms |
9836 KB |
Output is correct |
45 |
Correct |
8 ms |
9836 KB |
Output is correct |
46 |
Correct |
9 ms |
9836 KB |
Output is correct |
47 |
Correct |
8 ms |
9836 KB |
Output is correct |
48 |
Correct |
9 ms |
9964 KB |
Output is correct |
49 |
Correct |
9 ms |
9964 KB |
Output is correct |
50 |
Correct |
8 ms |
9836 KB |
Output is correct |
51 |
Correct |
8 ms |
9836 KB |
Output is correct |
52 |
Correct |
8 ms |
9836 KB |
Output is correct |
53 |
Correct |
8 ms |
9836 KB |
Output is correct |
54 |
Correct |
8 ms |
9836 KB |
Output is correct |
55 |
Correct |
8 ms |
9836 KB |
Output is correct |
56 |
Correct |
13 ms |
9984 KB |
Output is correct |
57 |
Correct |
8 ms |
9964 KB |
Output is correct |
58 |
Correct |
14 ms |
9856 KB |
Output is correct |
59 |
Correct |
14 ms |
9836 KB |
Output is correct |
60 |
Correct |
8 ms |
9964 KB |
Output is correct |
61 |
Correct |
14 ms |
9836 KB |
Output is correct |
62 |
Correct |
8 ms |
9964 KB |
Output is correct |
63 |
Correct |
8 ms |
9836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9708 KB |
Output is correct |
2 |
Correct |
7 ms |
9708 KB |
Output is correct |
3 |
Correct |
7 ms |
9708 KB |
Output is correct |
4 |
Correct |
7 ms |
9708 KB |
Output is correct |
5 |
Correct |
7 ms |
9708 KB |
Output is correct |
6 |
Correct |
7 ms |
9708 KB |
Output is correct |
7 |
Correct |
7 ms |
9708 KB |
Output is correct |
8 |
Correct |
7 ms |
9708 KB |
Output is correct |
9 |
Correct |
7 ms |
9708 KB |
Output is correct |
10 |
Correct |
7 ms |
9728 KB |
Output is correct |
11 |
Correct |
7 ms |
9708 KB |
Output is correct |
12 |
Correct |
7 ms |
9708 KB |
Output is correct |
13 |
Correct |
7 ms |
9708 KB |
Output is correct |
14 |
Correct |
7 ms |
9708 KB |
Output is correct |
15 |
Correct |
7 ms |
9708 KB |
Output is correct |
16 |
Correct |
7 ms |
9728 KB |
Output is correct |
17 |
Correct |
7 ms |
9708 KB |
Output is correct |
18 |
Correct |
7 ms |
9708 KB |
Output is correct |
19 |
Correct |
7 ms |
9708 KB |
Output is correct |
20 |
Correct |
7 ms |
9708 KB |
Output is correct |
21 |
Correct |
7 ms |
9708 KB |
Output is correct |
22 |
Correct |
8 ms |
9836 KB |
Output is correct |
23 |
Correct |
8 ms |
9836 KB |
Output is correct |
24 |
Correct |
8 ms |
9836 KB |
Output is correct |
25 |
Correct |
8 ms |
9836 KB |
Output is correct |
26 |
Correct |
8 ms |
9836 KB |
Output is correct |
27 |
Correct |
8 ms |
9836 KB |
Output is correct |
28 |
Correct |
8 ms |
9836 KB |
Output is correct |
29 |
Correct |
8 ms |
9964 KB |
Output is correct |
30 |
Correct |
8 ms |
9964 KB |
Output is correct |
31 |
Correct |
8 ms |
9836 KB |
Output is correct |
32 |
Correct |
8 ms |
9836 KB |
Output is correct |
33 |
Correct |
9 ms |
9836 KB |
Output is correct |
34 |
Correct |
8 ms |
9856 KB |
Output is correct |
35 |
Correct |
8 ms |
9836 KB |
Output is correct |
36 |
Correct |
7 ms |
9836 KB |
Output is correct |
37 |
Correct |
9 ms |
9836 KB |
Output is correct |
38 |
Correct |
8 ms |
9836 KB |
Output is correct |
39 |
Correct |
8 ms |
9964 KB |
Output is correct |
40 |
Correct |
8 ms |
9836 KB |
Output is correct |
41 |
Correct |
8 ms |
9964 KB |
Output is correct |
42 |
Correct |
8 ms |
9836 KB |
Output is correct |
43 |
Correct |
8 ms |
9836 KB |
Output is correct |
44 |
Correct |
8 ms |
9836 KB |
Output is correct |
45 |
Correct |
8 ms |
9836 KB |
Output is correct |
46 |
Correct |
9 ms |
9836 KB |
Output is correct |
47 |
Correct |
8 ms |
9836 KB |
Output is correct |
48 |
Correct |
9 ms |
9964 KB |
Output is correct |
49 |
Correct |
9 ms |
9964 KB |
Output is correct |
50 |
Correct |
8 ms |
9836 KB |
Output is correct |
51 |
Correct |
8 ms |
9836 KB |
Output is correct |
52 |
Correct |
8 ms |
9836 KB |
Output is correct |
53 |
Correct |
8 ms |
9836 KB |
Output is correct |
54 |
Correct |
8 ms |
9836 KB |
Output is correct |
55 |
Correct |
8 ms |
9836 KB |
Output is correct |
56 |
Correct |
13 ms |
9984 KB |
Output is correct |
57 |
Correct |
8 ms |
9964 KB |
Output is correct |
58 |
Correct |
14 ms |
9856 KB |
Output is correct |
59 |
Correct |
14 ms |
9836 KB |
Output is correct |
60 |
Correct |
8 ms |
9964 KB |
Output is correct |
61 |
Correct |
14 ms |
9836 KB |
Output is correct |
62 |
Correct |
8 ms |
9964 KB |
Output is correct |
63 |
Correct |
8 ms |
9836 KB |
Output is correct |
64 |
Correct |
232 ms |
20528 KB |
Output is correct |
65 |
Correct |
234 ms |
23340 KB |
Output is correct |
66 |
Correct |
226 ms |
23324 KB |
Output is correct |
67 |
Correct |
227 ms |
23228 KB |
Output is correct |
68 |
Correct |
232 ms |
23344 KB |
Output is correct |
69 |
Correct |
239 ms |
23208 KB |
Output is correct |
70 |
Correct |
230 ms |
23228 KB |
Output is correct |
71 |
Correct |
232 ms |
23096 KB |
Output is correct |
72 |
Correct |
229 ms |
21672 KB |
Output is correct |
73 |
Correct |
275 ms |
34860 KB |
Output is correct |
74 |
Correct |
274 ms |
34988 KB |
Output is correct |
75 |
Correct |
231 ms |
24488 KB |
Output is correct |
76 |
Correct |
237 ms |
24496 KB |
Output is correct |
77 |
Correct |
235 ms |
23332 KB |
Output is correct |
78 |
Correct |
232 ms |
23208 KB |
Output is correct |
79 |
Correct |
241 ms |
23344 KB |
Output is correct |
80 |
Correct |
243 ms |
23208 KB |
Output is correct |
81 |
Execution timed out |
1569 ms |
23264 KB |
Time limit exceeded |
82 |
Halted |
0 ms |
0 KB |
- |