# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
516484 |
2022-01-21T12:01:38 Z |
DJ035 |
Power Plant (JOI20_power) |
C++17 |
|
5 ms |
7500 KB |
#include <bits/stdc++.h>
#define MEM 111111
#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 |
2 ms |
3788 KB |
Output is correct |
2 |
Correct |
2 ms |
3788 KB |
Output is correct |
3 |
Correct |
2 ms |
3788 KB |
Output is correct |
4 |
Correct |
2 ms |
3788 KB |
Output is correct |
5 |
Correct |
2 ms |
3788 KB |
Output is correct |
6 |
Correct |
2 ms |
3792 KB |
Output is correct |
7 |
Correct |
2 ms |
3792 KB |
Output is correct |
8 |
Correct |
2 ms |
3788 KB |
Output is correct |
9 |
Correct |
2 ms |
3788 KB |
Output is correct |
10 |
Correct |
2 ms |
3788 KB |
Output is correct |
11 |
Correct |
2 ms |
3788 KB |
Output is correct |
12 |
Correct |
2 ms |
3788 KB |
Output is correct |
13 |
Correct |
2 ms |
3788 KB |
Output is correct |
14 |
Correct |
2 ms |
3788 KB |
Output is correct |
15 |
Correct |
2 ms |
3788 KB |
Output is correct |
16 |
Correct |
3 ms |
3788 KB |
Output is correct |
17 |
Correct |
2 ms |
3788 KB |
Output is correct |
18 |
Correct |
2 ms |
3792 KB |
Output is correct |
19 |
Correct |
2 ms |
3788 KB |
Output is correct |
20 |
Correct |
2 ms |
3788 KB |
Output is correct |
21 |
Correct |
2 ms |
3788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3788 KB |
Output is correct |
2 |
Correct |
2 ms |
3788 KB |
Output is correct |
3 |
Correct |
2 ms |
3788 KB |
Output is correct |
4 |
Correct |
2 ms |
3788 KB |
Output is correct |
5 |
Correct |
2 ms |
3788 KB |
Output is correct |
6 |
Correct |
2 ms |
3792 KB |
Output is correct |
7 |
Correct |
2 ms |
3792 KB |
Output is correct |
8 |
Correct |
2 ms |
3788 KB |
Output is correct |
9 |
Correct |
2 ms |
3788 KB |
Output is correct |
10 |
Correct |
2 ms |
3788 KB |
Output is correct |
11 |
Correct |
2 ms |
3788 KB |
Output is correct |
12 |
Correct |
2 ms |
3788 KB |
Output is correct |
13 |
Correct |
2 ms |
3788 KB |
Output is correct |
14 |
Correct |
2 ms |
3788 KB |
Output is correct |
15 |
Correct |
2 ms |
3788 KB |
Output is correct |
16 |
Correct |
3 ms |
3788 KB |
Output is correct |
17 |
Correct |
2 ms |
3788 KB |
Output is correct |
18 |
Correct |
2 ms |
3792 KB |
Output is correct |
19 |
Correct |
2 ms |
3788 KB |
Output is correct |
20 |
Correct |
2 ms |
3788 KB |
Output is correct |
21 |
Correct |
2 ms |
3788 KB |
Output is correct |
22 |
Correct |
2 ms |
3808 KB |
Output is correct |
23 |
Correct |
2 ms |
3800 KB |
Output is correct |
24 |
Correct |
3 ms |
3788 KB |
Output is correct |
25 |
Correct |
3 ms |
3788 KB |
Output is correct |
26 |
Correct |
3 ms |
3788 KB |
Output is correct |
27 |
Correct |
2 ms |
3788 KB |
Output is correct |
28 |
Correct |
3 ms |
3800 KB |
Output is correct |
29 |
Correct |
4 ms |
3916 KB |
Output is correct |
30 |
Correct |
3 ms |
3932 KB |
Output is correct |
31 |
Correct |
3 ms |
3788 KB |
Output is correct |
32 |
Correct |
3 ms |
3788 KB |
Output is correct |
33 |
Correct |
2 ms |
3788 KB |
Output is correct |
34 |
Correct |
2 ms |
3788 KB |
Output is correct |
35 |
Correct |
2 ms |
3788 KB |
Output is correct |
36 |
Correct |
3 ms |
3788 KB |
Output is correct |
37 |
Correct |
2 ms |
3788 KB |
Output is correct |
38 |
Correct |
2 ms |
3808 KB |
Output is correct |
39 |
Correct |
2 ms |
3916 KB |
Output is correct |
40 |
Correct |
3 ms |
3916 KB |
Output is correct |
41 |
Correct |
3 ms |
3936 KB |
Output is correct |
42 |
Correct |
3 ms |
3788 KB |
Output is correct |
43 |
Correct |
2 ms |
3788 KB |
Output is correct |
44 |
Correct |
3 ms |
3916 KB |
Output is correct |
45 |
Correct |
3 ms |
3800 KB |
Output is correct |
46 |
Correct |
3 ms |
3808 KB |
Output is correct |
47 |
Correct |
2 ms |
3788 KB |
Output is correct |
48 |
Correct |
2 ms |
3916 KB |
Output is correct |
49 |
Correct |
5 ms |
3856 KB |
Output is correct |
50 |
Correct |
2 ms |
3916 KB |
Output is correct |
51 |
Correct |
2 ms |
3916 KB |
Output is correct |
52 |
Correct |
2 ms |
3788 KB |
Output is correct |
53 |
Correct |
2 ms |
3788 KB |
Output is correct |
54 |
Correct |
3 ms |
3916 KB |
Output is correct |
55 |
Correct |
2 ms |
3788 KB |
Output is correct |
56 |
Correct |
3 ms |
3788 KB |
Output is correct |
57 |
Correct |
3 ms |
3916 KB |
Output is correct |
58 |
Correct |
3 ms |
3804 KB |
Output is correct |
59 |
Correct |
4 ms |
3788 KB |
Output is correct |
60 |
Correct |
2 ms |
3932 KB |
Output is correct |
61 |
Correct |
2 ms |
3788 KB |
Output is correct |
62 |
Correct |
2 ms |
3916 KB |
Output is correct |
63 |
Correct |
3 ms |
3788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3788 KB |
Output is correct |
2 |
Correct |
2 ms |
3788 KB |
Output is correct |
3 |
Correct |
2 ms |
3788 KB |
Output is correct |
4 |
Correct |
2 ms |
3788 KB |
Output is correct |
5 |
Correct |
2 ms |
3788 KB |
Output is correct |
6 |
Correct |
2 ms |
3792 KB |
Output is correct |
7 |
Correct |
2 ms |
3792 KB |
Output is correct |
8 |
Correct |
2 ms |
3788 KB |
Output is correct |
9 |
Correct |
2 ms |
3788 KB |
Output is correct |
10 |
Correct |
2 ms |
3788 KB |
Output is correct |
11 |
Correct |
2 ms |
3788 KB |
Output is correct |
12 |
Correct |
2 ms |
3788 KB |
Output is correct |
13 |
Correct |
2 ms |
3788 KB |
Output is correct |
14 |
Correct |
2 ms |
3788 KB |
Output is correct |
15 |
Correct |
2 ms |
3788 KB |
Output is correct |
16 |
Correct |
3 ms |
3788 KB |
Output is correct |
17 |
Correct |
2 ms |
3788 KB |
Output is correct |
18 |
Correct |
2 ms |
3792 KB |
Output is correct |
19 |
Correct |
2 ms |
3788 KB |
Output is correct |
20 |
Correct |
2 ms |
3788 KB |
Output is correct |
21 |
Correct |
2 ms |
3788 KB |
Output is correct |
22 |
Correct |
2 ms |
3808 KB |
Output is correct |
23 |
Correct |
2 ms |
3800 KB |
Output is correct |
24 |
Correct |
3 ms |
3788 KB |
Output is correct |
25 |
Correct |
3 ms |
3788 KB |
Output is correct |
26 |
Correct |
3 ms |
3788 KB |
Output is correct |
27 |
Correct |
2 ms |
3788 KB |
Output is correct |
28 |
Correct |
3 ms |
3800 KB |
Output is correct |
29 |
Correct |
4 ms |
3916 KB |
Output is correct |
30 |
Correct |
3 ms |
3932 KB |
Output is correct |
31 |
Correct |
3 ms |
3788 KB |
Output is correct |
32 |
Correct |
3 ms |
3788 KB |
Output is correct |
33 |
Correct |
2 ms |
3788 KB |
Output is correct |
34 |
Correct |
2 ms |
3788 KB |
Output is correct |
35 |
Correct |
2 ms |
3788 KB |
Output is correct |
36 |
Correct |
3 ms |
3788 KB |
Output is correct |
37 |
Correct |
2 ms |
3788 KB |
Output is correct |
38 |
Correct |
2 ms |
3808 KB |
Output is correct |
39 |
Correct |
2 ms |
3916 KB |
Output is correct |
40 |
Correct |
3 ms |
3916 KB |
Output is correct |
41 |
Correct |
3 ms |
3936 KB |
Output is correct |
42 |
Correct |
3 ms |
3788 KB |
Output is correct |
43 |
Correct |
2 ms |
3788 KB |
Output is correct |
44 |
Correct |
3 ms |
3916 KB |
Output is correct |
45 |
Correct |
3 ms |
3800 KB |
Output is correct |
46 |
Correct |
3 ms |
3808 KB |
Output is correct |
47 |
Correct |
2 ms |
3788 KB |
Output is correct |
48 |
Correct |
2 ms |
3916 KB |
Output is correct |
49 |
Correct |
5 ms |
3856 KB |
Output is correct |
50 |
Correct |
2 ms |
3916 KB |
Output is correct |
51 |
Correct |
2 ms |
3916 KB |
Output is correct |
52 |
Correct |
2 ms |
3788 KB |
Output is correct |
53 |
Correct |
2 ms |
3788 KB |
Output is correct |
54 |
Correct |
3 ms |
3916 KB |
Output is correct |
55 |
Correct |
2 ms |
3788 KB |
Output is correct |
56 |
Correct |
3 ms |
3788 KB |
Output is correct |
57 |
Correct |
3 ms |
3916 KB |
Output is correct |
58 |
Correct |
3 ms |
3804 KB |
Output is correct |
59 |
Correct |
4 ms |
3788 KB |
Output is correct |
60 |
Correct |
2 ms |
3932 KB |
Output is correct |
61 |
Correct |
2 ms |
3788 KB |
Output is correct |
62 |
Correct |
2 ms |
3916 KB |
Output is correct |
63 |
Correct |
3 ms |
3788 KB |
Output is correct |
64 |
Runtime error |
5 ms |
7500 KB |
Execution killed with signal 11 |
65 |
Halted |
0 ms |
0 KB |
- |