Submission #516321

# Submission time Handle Problem Language Result Execution time Memory
516321 2022-01-21T05:31:34 Z jk410 Power Plant (JOI20_power) C++17
100 / 100
149 ms 29552 KB
#include <bits/stdc++.h>
using namespace std;
int N,Ans;
int A[200001],DP[200001];
string S;
vector<int> Edge[200001];
void dfs(int v,int par=0){
    int sum=0,mx=0;
    for (int i:Edge[v]){
        if (i==par)
            continue;
        dfs(i,v);
        sum+=DP[i];
        mx=max(mx,DP[i]);
    }
    DP[v]=max(sum-A[v],A[v]);
    Ans=max({Ans,sum-A[v],mx+A[v]});
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>N;
    for (int i=1,a,b; i<N; i++){
        cin>>a>>b;
        Edge[a].push_back(b);
        Edge[b].push_back(a);
    }
    cin>>S;
    for (int i=1; i<=N; i++)
        A[i]=(S[i-1]-'0');
    dfs(1);
    cout<<Ans;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 2 ms 4940 KB Output is correct
4 Correct 2 ms 4940 KB Output is correct
5 Correct 2 ms 4940 KB Output is correct
6 Correct 2 ms 4940 KB Output is correct
7 Correct 2 ms 4940 KB Output is correct
8 Correct 2 ms 4940 KB Output is correct
9 Correct 2 ms 4940 KB Output is correct
10 Correct 2 ms 4940 KB Output is correct
11 Correct 2 ms 4940 KB Output is correct
12 Correct 2 ms 4940 KB Output is correct
13 Correct 2 ms 4940 KB Output is correct
14 Correct 2 ms 4940 KB Output is correct
15 Correct 2 ms 5020 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 2 ms 4940 KB Output is correct
18 Correct 4 ms 4940 KB Output is correct
19 Correct 2 ms 4940 KB Output is correct
20 Correct 2 ms 4940 KB Output is correct
21 Correct 2 ms 4940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 2 ms 4940 KB Output is correct
4 Correct 2 ms 4940 KB Output is correct
5 Correct 2 ms 4940 KB Output is correct
6 Correct 2 ms 4940 KB Output is correct
7 Correct 2 ms 4940 KB Output is correct
8 Correct 2 ms 4940 KB Output is correct
9 Correct 2 ms 4940 KB Output is correct
10 Correct 2 ms 4940 KB Output is correct
11 Correct 2 ms 4940 KB Output is correct
12 Correct 2 ms 4940 KB Output is correct
13 Correct 2 ms 4940 KB Output is correct
14 Correct 2 ms 4940 KB Output is correct
15 Correct 2 ms 5020 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 2 ms 4940 KB Output is correct
18 Correct 4 ms 4940 KB Output is correct
19 Correct 2 ms 4940 KB Output is correct
20 Correct 2 ms 4940 KB Output is correct
21 Correct 2 ms 4940 KB Output is correct
22 Correct 3 ms 5068 KB Output is correct
23 Correct 3 ms 5068 KB Output is correct
24 Correct 3 ms 5044 KB Output is correct
25 Correct 3 ms 5068 KB Output is correct
26 Correct 3 ms 5068 KB Output is correct
27 Correct 3 ms 5068 KB Output is correct
28 Correct 3 ms 5068 KB Output is correct
29 Correct 3 ms 5196 KB Output is correct
30 Correct 3 ms 5068 KB Output is correct
31 Correct 3 ms 5052 KB Output is correct
32 Correct 3 ms 5068 KB Output is correct
33 Correct 3 ms 5068 KB Output is correct
34 Correct 3 ms 5068 KB Output is correct
35 Correct 3 ms 5068 KB Output is correct
36 Correct 3 ms 5068 KB Output is correct
37 Correct 3 ms 5068 KB Output is correct
38 Correct 4 ms 5068 KB Output is correct
39 Correct 4 ms 5068 KB Output is correct
40 Correct 3 ms 5068 KB Output is correct
41 Correct 3 ms 5068 KB Output is correct
42 Correct 4 ms 5120 KB Output is correct
43 Correct 3 ms 5068 KB Output is correct
44 Correct 3 ms 5068 KB Output is correct
45 Correct 3 ms 5068 KB Output is correct
46 Correct 3 ms 5068 KB Output is correct
47 Correct 3 ms 5068 KB Output is correct
48 Correct 3 ms 5068 KB Output is correct
49 Correct 3 ms 5068 KB Output is correct
50 Correct 3 ms 5068 KB Output is correct
51 Correct 3 ms 5068 KB Output is correct
52 Correct 3 ms 5068 KB Output is correct
53 Correct 3 ms 5068 KB Output is correct
54 Correct 3 ms 5068 KB Output is correct
55 Correct 3 ms 5068 KB Output is correct
56 Correct 3 ms 5008 KB Output is correct
57 Correct 3 ms 5196 KB Output is correct
58 Correct 4 ms 5056 KB Output is correct
59 Correct 3 ms 5068 KB Output is correct
60 Correct 3 ms 5068 KB Output is correct
61 Correct 5 ms 5120 KB Output is correct
62 Correct 4 ms 5196 KB Output is correct
63 Correct 3 ms 5068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 2 ms 4940 KB Output is correct
4 Correct 2 ms 4940 KB Output is correct
5 Correct 2 ms 4940 KB Output is correct
6 Correct 2 ms 4940 KB Output is correct
7 Correct 2 ms 4940 KB Output is correct
8 Correct 2 ms 4940 KB Output is correct
9 Correct 2 ms 4940 KB Output is correct
10 Correct 2 ms 4940 KB Output is correct
11 Correct 2 ms 4940 KB Output is correct
12 Correct 2 ms 4940 KB Output is correct
13 Correct 2 ms 4940 KB Output is correct
14 Correct 2 ms 4940 KB Output is correct
15 Correct 2 ms 5020 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 2 ms 4940 KB Output is correct
18 Correct 4 ms 4940 KB Output is correct
19 Correct 2 ms 4940 KB Output is correct
20 Correct 2 ms 4940 KB Output is correct
21 Correct 2 ms 4940 KB Output is correct
22 Correct 3 ms 5068 KB Output is correct
23 Correct 3 ms 5068 KB Output is correct
24 Correct 3 ms 5044 KB Output is correct
25 Correct 3 ms 5068 KB Output is correct
26 Correct 3 ms 5068 KB Output is correct
27 Correct 3 ms 5068 KB Output is correct
28 Correct 3 ms 5068 KB Output is correct
29 Correct 3 ms 5196 KB Output is correct
30 Correct 3 ms 5068 KB Output is correct
31 Correct 3 ms 5052 KB Output is correct
32 Correct 3 ms 5068 KB Output is correct
33 Correct 3 ms 5068 KB Output is correct
34 Correct 3 ms 5068 KB Output is correct
35 Correct 3 ms 5068 KB Output is correct
36 Correct 3 ms 5068 KB Output is correct
37 Correct 3 ms 5068 KB Output is correct
38 Correct 4 ms 5068 KB Output is correct
39 Correct 4 ms 5068 KB Output is correct
40 Correct 3 ms 5068 KB Output is correct
41 Correct 3 ms 5068 KB Output is correct
42 Correct 4 ms 5120 KB Output is correct
43 Correct 3 ms 5068 KB Output is correct
44 Correct 3 ms 5068 KB Output is correct
45 Correct 3 ms 5068 KB Output is correct
46 Correct 3 ms 5068 KB Output is correct
47 Correct 3 ms 5068 KB Output is correct
48 Correct 3 ms 5068 KB Output is correct
49 Correct 3 ms 5068 KB Output is correct
50 Correct 3 ms 5068 KB Output is correct
51 Correct 3 ms 5068 KB Output is correct
52 Correct 3 ms 5068 KB Output is correct
53 Correct 3 ms 5068 KB Output is correct
54 Correct 3 ms 5068 KB Output is correct
55 Correct 3 ms 5068 KB Output is correct
56 Correct 3 ms 5008 KB Output is correct
57 Correct 3 ms 5196 KB Output is correct
58 Correct 4 ms 5056 KB Output is correct
59 Correct 3 ms 5068 KB Output is correct
60 Correct 3 ms 5068 KB Output is correct
61 Correct 5 ms 5120 KB Output is correct
62 Correct 4 ms 5196 KB Output is correct
63 Correct 3 ms 5068 KB Output is correct
64 Correct 109 ms 15920 KB Output is correct
65 Correct 122 ms 15876 KB Output is correct
66 Correct 111 ms 15888 KB Output is correct
67 Correct 111 ms 15920 KB Output is correct
68 Correct 143 ms 15948 KB Output is correct
69 Correct 110 ms 15960 KB Output is correct
70 Correct 123 ms 15868 KB Output is correct
71 Correct 116 ms 15860 KB Output is correct
72 Correct 128 ms 15872 KB Output is correct
73 Correct 131 ms 28564 KB Output is correct
74 Correct 149 ms 28484 KB Output is correct
75 Correct 104 ms 15788 KB Output is correct
76 Correct 117 ms 15748 KB Output is correct
77 Correct 119 ms 15768 KB Output is correct
78 Correct 115 ms 15748 KB Output is correct
79 Correct 123 ms 15816 KB Output is correct
80 Correct 121 ms 15748 KB Output is correct
81 Correct 112 ms 16304 KB Output is correct
82 Correct 97 ms 15984 KB Output is correct
83 Correct 134 ms 21052 KB Output is correct
84 Correct 119 ms 23160 KB Output is correct
85 Correct 130 ms 22868 KB Output is correct
86 Correct 110 ms 17284 KB Output is correct
87 Correct 120 ms 16628 KB Output is correct
88 Correct 105 ms 17184 KB Output is correct
89 Correct 114 ms 17212 KB Output is correct
90 Correct 122 ms 17080 KB Output is correct
91 Correct 104 ms 17188 KB Output is correct
92 Correct 121 ms 17716 KB Output is correct
93 Correct 106 ms 19912 KB Output is correct
94 Correct 100 ms 21668 KB Output is correct
95 Correct 105 ms 20304 KB Output is correct
96 Correct 107 ms 18548 KB Output is correct
97 Correct 118 ms 17044 KB Output is correct
98 Correct 108 ms 16580 KB Output is correct
99 Correct 105 ms 16280 KB Output is correct
100 Correct 118 ms 19516 KB Output is correct
101 Correct 105 ms 17376 KB Output is correct
102 Correct 109 ms 16936 KB Output is correct
103 Correct 110 ms 16568 KB Output is correct
104 Correct 72 ms 16800 KB Output is correct
105 Correct 124 ms 25296 KB Output is correct
106 Correct 67 ms 16704 KB Output is correct
107 Correct 68 ms 16688 KB Output is correct
108 Correct 138 ms 29372 KB Output is correct
109 Correct 75 ms 16812 KB Output is correct
110 Correct 128 ms 29552 KB Output is correct
111 Correct 95 ms 15828 KB Output is correct