Submission #763287

# Submission time Handle Problem Language Result Execution time Memory
763287 2023-06-22T07:45:03 Z vjudge1 Power Plant (JOI20_power) C++14
100 / 100
181 ms 27732 KB
#include <bits/stdc++.h> 
using namespace std;
#define ll long long
#define fi first
#define se second
#define ii pair<ll,ll>
const ll maxn=2e5+2;

vector <int> adj[maxn];

int dp[maxn];
int gen[maxn];
int sub[maxn];
int ans;

void dfs(int u, int pre){
    //cout<<u<<endl;
    int mx=0;
    int sum=0;
    for (int v: adj[u]){
        if (v!=u&&v!=pre){
            dfs(v,u);
            mx=max(mx,dp[v]);
            sum+=dp[v];
            sub[u]+=sub[v];
        }
    }
    dp[u]=max(gen[u],sum-gen[u]);
    ans=max(ans,max(dp[u],mx+gen[u]));
}
int main(){
    int n; cin>>n;
    for (int i=1;i<n;++i){
        int x,y; cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }   
    string s; cin>>s;
    for (int i=1;i<=n;++i){
        gen[i]=s[i-1]-'0';
    }
    //cout<<s;
    dfs(1,1);
    //for (int i=1;i<=n;++i) cout<<i<<" "<<dp[i]<<"\n";
    cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 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 2 ms 4948 KB Output is correct
8 Correct 2 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 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 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 2 ms 4948 KB Output is correct
8 Correct 2 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 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 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 5108 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 5196 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 3 ms 5076 KB Output is correct
41 Correct 3 ms 5076 KB Output is correct
42 Correct 3 ms 5076 KB Output is correct
43 Correct 3 ms 5076 KB Output is correct
44 Correct 3 ms 5076 KB Output is correct
45 Correct 3 ms 5076 KB Output is correct
46 Correct 3 ms 5076 KB Output is correct
47 Correct 3 ms 5076 KB Output is correct
48 Correct 3 ms 5076 KB Output is correct
49 Correct 3 ms 5076 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 5 ms 5060 KB Output is correct
56 Correct 3 ms 5112 KB Output is correct
57 Correct 3 ms 5204 KB Output is correct
58 Correct 3 ms 5112 KB Output is correct
59 Correct 3 ms 5076 KB Output is correct
60 Correct 3 ms 5076 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 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 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 2 ms 4948 KB Output is correct
8 Correct 2 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 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 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 5108 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 5196 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 3 ms 5076 KB Output is correct
41 Correct 3 ms 5076 KB Output is correct
42 Correct 3 ms 5076 KB Output is correct
43 Correct 3 ms 5076 KB Output is correct
44 Correct 3 ms 5076 KB Output is correct
45 Correct 3 ms 5076 KB Output is correct
46 Correct 3 ms 5076 KB Output is correct
47 Correct 3 ms 5076 KB Output is correct
48 Correct 3 ms 5076 KB Output is correct
49 Correct 3 ms 5076 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 5 ms 5060 KB Output is correct
56 Correct 3 ms 5112 KB Output is correct
57 Correct 3 ms 5204 KB Output is correct
58 Correct 3 ms 5112 KB Output is correct
59 Correct 3 ms 5076 KB Output is correct
60 Correct 3 ms 5076 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 130 ms 14032 KB Output is correct
65 Correct 131 ms 14008 KB Output is correct
66 Correct 137 ms 14016 KB Output is correct
67 Correct 132 ms 14020 KB Output is correct
68 Correct 127 ms 13932 KB Output is correct
69 Correct 126 ms 14036 KB Output is correct
70 Correct 129 ms 14000 KB Output is correct
71 Correct 140 ms 13996 KB Output is correct
72 Correct 134 ms 14000 KB Output is correct
73 Correct 148 ms 26556 KB Output is correct
74 Correct 145 ms 26552 KB Output is correct
75 Correct 126 ms 13916 KB Output is correct
76 Correct 127 ms 13900 KB Output is correct
77 Correct 129 ms 13832 KB Output is correct
78 Correct 139 ms 13932 KB Output is correct
79 Correct 146 ms 13824 KB Output is correct
80 Correct 145 ms 13932 KB Output is correct
81 Correct 119 ms 14420 KB Output is correct
82 Correct 124 ms 14172 KB Output is correct
83 Correct 149 ms 19072 KB Output is correct
84 Correct 163 ms 21188 KB Output is correct
85 Correct 150 ms 20932 KB Output is correct
86 Correct 140 ms 15340 KB Output is correct
87 Correct 134 ms 14748 KB Output is correct
88 Correct 141 ms 15240 KB Output is correct
89 Correct 127 ms 15200 KB Output is correct
90 Correct 134 ms 15044 KB Output is correct
91 Correct 128 ms 15272 KB Output is correct
92 Correct 136 ms 15560 KB Output is correct
93 Correct 125 ms 18004 KB Output is correct
94 Correct 125 ms 19844 KB Output is correct
95 Correct 125 ms 18392 KB Output is correct
96 Correct 127 ms 16484 KB Output is correct
97 Correct 126 ms 15080 KB Output is correct
98 Correct 124 ms 14500 KB Output is correct
99 Correct 123 ms 14300 KB Output is correct
100 Correct 130 ms 17524 KB Output is correct
101 Correct 142 ms 15612 KB Output is correct
102 Correct 123 ms 14768 KB Output is correct
103 Correct 127 ms 14592 KB Output is correct
104 Correct 106 ms 13996 KB Output is correct
105 Correct 157 ms 23436 KB Output is correct
106 Correct 105 ms 14028 KB Output is correct
107 Correct 101 ms 14040 KB Output is correct
108 Correct 181 ms 27308 KB Output is correct
109 Correct 107 ms 13980 KB Output is correct
110 Correct 143 ms 27732 KB Output is correct
111 Correct 124 ms 13844 KB Output is correct