# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
516485 |
2022-01-21T12:03:45 Z |
DJ035 |
Power Plant (JOI20_power) |
C++17 |
|
153 ms |
27696 KB |
#include <bits/stdc++.h>
#define MEM 222222
#define sanic ios_base::sync_with_stdio(0)
#define x first
#define y second
#define pf push_front
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz size()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
const ll MOD = 1e9+7;
const ll INF = 2e14+7;
ll mul(ll a, ll b){
return ((a*b)%MOD+MOD)%MOD;
}
ll add(ll a, ll b){
return ((a+b)%MOD+MOD)%MOD;
}
ll t,n,m,q,k;
ll dp[MEM];
ll ans;
vector<ll> g[MEM];
string s;
ll DP(ll c, ll p){
ll& ret = dp[c];
if(ret!=-1) return ret;
ll dsum=0, dmx=0;
for(ll nt:g[c]){
if(nt==p) continue;
ll o=DP(nt, c);
dsum += o;
dmx = max(o, dmx);
}
ll ct=(ll)(s[c-1]-'0');
ret = max(dsum-ct, ct);
ans = max({ans, dmx+ct, dsum-ct});
//cout << c << ' ' << ret << ' ' << ans << ' ' << dsum << ' ' << dmx << '\n';
return ret;
}
signed main(){
sanic; cin.tie(0); cout.tie(0);
memset(dp, -1, sizeof(dp));
cin >> n;
for(int i=1; i<n; i++){
ll q1,q2;
cin >> q1 >> q2;
g[q1].pb(q2);
g[q2].pb(q1);
}
cin >> s;
DP(1, -1);
cout << ans;
}
/*
6
2 3
4 3
1 3
3 5
6 2
110011
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7244 KB |
Output is correct |
2 |
Correct |
3 ms |
7244 KB |
Output is correct |
3 |
Correct |
3 ms |
7244 KB |
Output is correct |
4 |
Correct |
3 ms |
7244 KB |
Output is correct |
5 |
Correct |
3 ms |
7244 KB |
Output is correct |
6 |
Correct |
4 ms |
7204 KB |
Output is correct |
7 |
Correct |
4 ms |
7244 KB |
Output is correct |
8 |
Correct |
4 ms |
7252 KB |
Output is correct |
9 |
Correct |
3 ms |
7244 KB |
Output is correct |
10 |
Correct |
3 ms |
7244 KB |
Output is correct |
11 |
Correct |
4 ms |
7160 KB |
Output is correct |
12 |
Correct |
4 ms |
7152 KB |
Output is correct |
13 |
Correct |
3 ms |
7244 KB |
Output is correct |
14 |
Correct |
3 ms |
7244 KB |
Output is correct |
15 |
Correct |
3 ms |
7244 KB |
Output is correct |
16 |
Correct |
3 ms |
7244 KB |
Output is correct |
17 |
Correct |
3 ms |
7244 KB |
Output is correct |
18 |
Correct |
3 ms |
7244 KB |
Output is correct |
19 |
Correct |
4 ms |
7244 KB |
Output is correct |
20 |
Correct |
3 ms |
7244 KB |
Output is correct |
21 |
Correct |
3 ms |
7244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7244 KB |
Output is correct |
2 |
Correct |
3 ms |
7244 KB |
Output is correct |
3 |
Correct |
3 ms |
7244 KB |
Output is correct |
4 |
Correct |
3 ms |
7244 KB |
Output is correct |
5 |
Correct |
3 ms |
7244 KB |
Output is correct |
6 |
Correct |
4 ms |
7204 KB |
Output is correct |
7 |
Correct |
4 ms |
7244 KB |
Output is correct |
8 |
Correct |
4 ms |
7252 KB |
Output is correct |
9 |
Correct |
3 ms |
7244 KB |
Output is correct |
10 |
Correct |
3 ms |
7244 KB |
Output is correct |
11 |
Correct |
4 ms |
7160 KB |
Output is correct |
12 |
Correct |
4 ms |
7152 KB |
Output is correct |
13 |
Correct |
3 ms |
7244 KB |
Output is correct |
14 |
Correct |
3 ms |
7244 KB |
Output is correct |
15 |
Correct |
3 ms |
7244 KB |
Output is correct |
16 |
Correct |
3 ms |
7244 KB |
Output is correct |
17 |
Correct |
3 ms |
7244 KB |
Output is correct |
18 |
Correct |
3 ms |
7244 KB |
Output is correct |
19 |
Correct |
4 ms |
7244 KB |
Output is correct |
20 |
Correct |
3 ms |
7244 KB |
Output is correct |
21 |
Correct |
3 ms |
7244 KB |
Output is correct |
22 |
Correct |
4 ms |
7244 KB |
Output is correct |
23 |
Correct |
4 ms |
7244 KB |
Output is correct |
24 |
Correct |
4 ms |
7244 KB |
Output is correct |
25 |
Correct |
4 ms |
7244 KB |
Output is correct |
26 |
Correct |
4 ms |
7244 KB |
Output is correct |
27 |
Correct |
4 ms |
7244 KB |
Output is correct |
28 |
Correct |
4 ms |
7244 KB |
Output is correct |
29 |
Correct |
4 ms |
7348 KB |
Output is correct |
30 |
Correct |
4 ms |
7372 KB |
Output is correct |
31 |
Correct |
4 ms |
7244 KB |
Output is correct |
32 |
Correct |
4 ms |
7244 KB |
Output is correct |
33 |
Correct |
4 ms |
7244 KB |
Output is correct |
34 |
Correct |
4 ms |
7244 KB |
Output is correct |
35 |
Correct |
4 ms |
7244 KB |
Output is correct |
36 |
Correct |
4 ms |
7244 KB |
Output is correct |
37 |
Correct |
4 ms |
7244 KB |
Output is correct |
38 |
Correct |
6 ms |
7244 KB |
Output is correct |
39 |
Correct |
4 ms |
7372 KB |
Output is correct |
40 |
Correct |
4 ms |
7372 KB |
Output is correct |
41 |
Correct |
5 ms |
7372 KB |
Output is correct |
42 |
Correct |
4 ms |
7372 KB |
Output is correct |
43 |
Correct |
4 ms |
7244 KB |
Output is correct |
44 |
Correct |
4 ms |
7372 KB |
Output is correct |
45 |
Correct |
4 ms |
7372 KB |
Output is correct |
46 |
Correct |
4 ms |
7372 KB |
Output is correct |
47 |
Correct |
4 ms |
7244 KB |
Output is correct |
48 |
Correct |
4 ms |
7372 KB |
Output is correct |
49 |
Correct |
4 ms |
7388 KB |
Output is correct |
50 |
Correct |
4 ms |
7388 KB |
Output is correct |
51 |
Correct |
4 ms |
7372 KB |
Output is correct |
52 |
Correct |
5 ms |
7244 KB |
Output is correct |
53 |
Correct |
4 ms |
7372 KB |
Output is correct |
54 |
Correct |
4 ms |
7372 KB |
Output is correct |
55 |
Correct |
5 ms |
7244 KB |
Output is correct |
56 |
Correct |
6 ms |
7244 KB |
Output is correct |
57 |
Correct |
4 ms |
7372 KB |
Output is correct |
58 |
Correct |
4 ms |
7244 KB |
Output is correct |
59 |
Correct |
4 ms |
7244 KB |
Output is correct |
60 |
Correct |
4 ms |
7372 KB |
Output is correct |
61 |
Correct |
4 ms |
7244 KB |
Output is correct |
62 |
Correct |
4 ms |
7420 KB |
Output is correct |
63 |
Correct |
4 ms |
7244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7244 KB |
Output is correct |
2 |
Correct |
3 ms |
7244 KB |
Output is correct |
3 |
Correct |
3 ms |
7244 KB |
Output is correct |
4 |
Correct |
3 ms |
7244 KB |
Output is correct |
5 |
Correct |
3 ms |
7244 KB |
Output is correct |
6 |
Correct |
4 ms |
7204 KB |
Output is correct |
7 |
Correct |
4 ms |
7244 KB |
Output is correct |
8 |
Correct |
4 ms |
7252 KB |
Output is correct |
9 |
Correct |
3 ms |
7244 KB |
Output is correct |
10 |
Correct |
3 ms |
7244 KB |
Output is correct |
11 |
Correct |
4 ms |
7160 KB |
Output is correct |
12 |
Correct |
4 ms |
7152 KB |
Output is correct |
13 |
Correct |
3 ms |
7244 KB |
Output is correct |
14 |
Correct |
3 ms |
7244 KB |
Output is correct |
15 |
Correct |
3 ms |
7244 KB |
Output is correct |
16 |
Correct |
3 ms |
7244 KB |
Output is correct |
17 |
Correct |
3 ms |
7244 KB |
Output is correct |
18 |
Correct |
3 ms |
7244 KB |
Output is correct |
19 |
Correct |
4 ms |
7244 KB |
Output is correct |
20 |
Correct |
3 ms |
7244 KB |
Output is correct |
21 |
Correct |
3 ms |
7244 KB |
Output is correct |
22 |
Correct |
4 ms |
7244 KB |
Output is correct |
23 |
Correct |
4 ms |
7244 KB |
Output is correct |
24 |
Correct |
4 ms |
7244 KB |
Output is correct |
25 |
Correct |
4 ms |
7244 KB |
Output is correct |
26 |
Correct |
4 ms |
7244 KB |
Output is correct |
27 |
Correct |
4 ms |
7244 KB |
Output is correct |
28 |
Correct |
4 ms |
7244 KB |
Output is correct |
29 |
Correct |
4 ms |
7348 KB |
Output is correct |
30 |
Correct |
4 ms |
7372 KB |
Output is correct |
31 |
Correct |
4 ms |
7244 KB |
Output is correct |
32 |
Correct |
4 ms |
7244 KB |
Output is correct |
33 |
Correct |
4 ms |
7244 KB |
Output is correct |
34 |
Correct |
4 ms |
7244 KB |
Output is correct |
35 |
Correct |
4 ms |
7244 KB |
Output is correct |
36 |
Correct |
4 ms |
7244 KB |
Output is correct |
37 |
Correct |
4 ms |
7244 KB |
Output is correct |
38 |
Correct |
6 ms |
7244 KB |
Output is correct |
39 |
Correct |
4 ms |
7372 KB |
Output is correct |
40 |
Correct |
4 ms |
7372 KB |
Output is correct |
41 |
Correct |
5 ms |
7372 KB |
Output is correct |
42 |
Correct |
4 ms |
7372 KB |
Output is correct |
43 |
Correct |
4 ms |
7244 KB |
Output is correct |
44 |
Correct |
4 ms |
7372 KB |
Output is correct |
45 |
Correct |
4 ms |
7372 KB |
Output is correct |
46 |
Correct |
4 ms |
7372 KB |
Output is correct |
47 |
Correct |
4 ms |
7244 KB |
Output is correct |
48 |
Correct |
4 ms |
7372 KB |
Output is correct |
49 |
Correct |
4 ms |
7388 KB |
Output is correct |
50 |
Correct |
4 ms |
7388 KB |
Output is correct |
51 |
Correct |
4 ms |
7372 KB |
Output is correct |
52 |
Correct |
5 ms |
7244 KB |
Output is correct |
53 |
Correct |
4 ms |
7372 KB |
Output is correct |
54 |
Correct |
4 ms |
7372 KB |
Output is correct |
55 |
Correct |
5 ms |
7244 KB |
Output is correct |
56 |
Correct |
6 ms |
7244 KB |
Output is correct |
57 |
Correct |
4 ms |
7372 KB |
Output is correct |
58 |
Correct |
4 ms |
7244 KB |
Output is correct |
59 |
Correct |
4 ms |
7244 KB |
Output is correct |
60 |
Correct |
4 ms |
7372 KB |
Output is correct |
61 |
Correct |
4 ms |
7244 KB |
Output is correct |
62 |
Correct |
4 ms |
7420 KB |
Output is correct |
63 |
Correct |
4 ms |
7244 KB |
Output is correct |
64 |
Correct |
107 ms |
15172 KB |
Output is correct |
65 |
Correct |
108 ms |
15120 KB |
Output is correct |
66 |
Correct |
118 ms |
15188 KB |
Output is correct |
67 |
Correct |
137 ms |
15136 KB |
Output is correct |
68 |
Correct |
122 ms |
15200 KB |
Output is correct |
69 |
Correct |
112 ms |
15140 KB |
Output is correct |
70 |
Correct |
137 ms |
15164 KB |
Output is correct |
71 |
Correct |
114 ms |
15048 KB |
Output is correct |
72 |
Correct |
111 ms |
15064 KB |
Output is correct |
73 |
Correct |
131 ms |
26592 KB |
Output is correct |
74 |
Correct |
153 ms |
26664 KB |
Output is correct |
75 |
Correct |
113 ms |
16384 KB |
Output is correct |
76 |
Correct |
112 ms |
16436 KB |
Output is correct |
77 |
Correct |
113 ms |
15108 KB |
Output is correct |
78 |
Correct |
127 ms |
15144 KB |
Output is correct |
79 |
Correct |
118 ms |
15156 KB |
Output is correct |
80 |
Correct |
125 ms |
15128 KB |
Output is correct |
81 |
Correct |
85 ms |
15072 KB |
Output is correct |
82 |
Correct |
97 ms |
15036 KB |
Output is correct |
83 |
Correct |
131 ms |
20188 KB |
Output is correct |
84 |
Correct |
136 ms |
22288 KB |
Output is correct |
85 |
Correct |
122 ms |
21876 KB |
Output is correct |
86 |
Correct |
115 ms |
16396 KB |
Output is correct |
87 |
Correct |
118 ms |
15744 KB |
Output is correct |
88 |
Correct |
115 ms |
15940 KB |
Output is correct |
89 |
Correct |
103 ms |
15888 KB |
Output is correct |
90 |
Correct |
101 ms |
15652 KB |
Output is correct |
91 |
Correct |
103 ms |
15984 KB |
Output is correct |
92 |
Correct |
102 ms |
16272 KB |
Output is correct |
93 |
Correct |
98 ms |
18612 KB |
Output is correct |
94 |
Correct |
124 ms |
20352 KB |
Output is correct |
95 |
Correct |
100 ms |
18964 KB |
Output is correct |
96 |
Correct |
113 ms |
17024 KB |
Output is correct |
97 |
Correct |
111 ms |
15528 KB |
Output is correct |
98 |
Correct |
99 ms |
15192 KB |
Output is correct |
99 |
Correct |
105 ms |
15268 KB |
Output is correct |
100 |
Correct |
124 ms |
17984 KB |
Output is correct |
101 |
Correct |
103 ms |
15968 KB |
Output is correct |
102 |
Correct |
104 ms |
15316 KB |
Output is correct |
103 |
Correct |
111 ms |
15396 KB |
Output is correct |
104 |
Correct |
75 ms |
15580 KB |
Output is correct |
105 |
Correct |
125 ms |
23456 KB |
Output is correct |
106 |
Correct |
61 ms |
15660 KB |
Output is correct |
107 |
Correct |
61 ms |
15584 KB |
Output is correct |
108 |
Correct |
124 ms |
27428 KB |
Output is correct |
109 |
Correct |
59 ms |
15540 KB |
Output is correct |
110 |
Correct |
134 ms |
27696 KB |
Output is correct |
111 |
Correct |
102 ms |
15036 KB |
Output is correct |