Submission #1031897

# Submission time Handle Problem Language Result Execution time Memory
1031897 2024-07-23T08:31:23 Z 정희우(#10963) Power Plant (JOI20_power) C++17
100 / 100
109 ms 27988 KB
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;
using lint = long long;
using intp = pair<int,int>;
using vint = vector<int>;

const int MAX_N=200010;

int n;
vint edge[MAX_N];
char val[MAX_N];

intp f(int v,int p)
{
    intp ret={0,0};
    int mr=0;
    for(auto v0 : edge[v])
        if(v0!=p)
        {
            intp r=f(v0,v);
            ret.first=max(ret.first,r.first);
            ret.second+=r.second;
            mr=max(mr,r.second);
        }
    ret.second=max(ret.second-val[v]+'0',val[v]-'0');
    ret.first=max(ret.first,max(ret.second,mr+val[v]-'0'));
    return ret;
}

int main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin >> n;
    for(int i=1;i<n;i++)
    {
        int u,v;
        cin >> u >> v;
        edge[u].push_back(v);
        edge[v].push_back(u);
    }
    cin >> val+1;
    cout << f(1,0).first;
    return 0;
}

Compilation message

power.cpp: In function 'int main()':
power.cpp:44:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   44 |     cin >> val+1;
      |            ~~~^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 3 ms 4952 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 3 ms 5160 KB Output is correct
5 Correct 2 ms 4952 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 3 ms 4956 KB Output is correct
9 Correct 3 ms 4956 KB Output is correct
10 Correct 3 ms 4952 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 5160 KB Output is correct
13 Correct 3 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 3 ms 4956 KB Output is correct
16 Correct 2 ms 4952 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 2 ms 5020 KB Output is correct
19 Correct 2 ms 4952 KB Output is correct
20 Correct 3 ms 4956 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 3 ms 4952 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 3 ms 5160 KB Output is correct
5 Correct 2 ms 4952 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 3 ms 4956 KB Output is correct
9 Correct 3 ms 4956 KB Output is correct
10 Correct 3 ms 4952 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 5160 KB Output is correct
13 Correct 3 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 3 ms 4956 KB Output is correct
16 Correct 2 ms 4952 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 2 ms 5020 KB Output is correct
19 Correct 2 ms 4952 KB Output is correct
20 Correct 3 ms 4956 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 3 ms 5172 KB Output is correct
23 Correct 2 ms 5212 KB Output is correct
24 Correct 4 ms 5212 KB Output is correct
25 Correct 4 ms 5212 KB Output is correct
26 Correct 3 ms 5212 KB Output is correct
27 Correct 4 ms 5356 KB Output is correct
28 Correct 2 ms 5212 KB Output is correct
29 Correct 2 ms 5212 KB Output is correct
30 Correct 3 ms 5212 KB Output is correct
31 Correct 3 ms 5244 KB Output is correct
32 Correct 2 ms 5212 KB Output is correct
33 Correct 3 ms 5208 KB Output is correct
34 Correct 3 ms 5208 KB Output is correct
35 Correct 2 ms 5212 KB Output is correct
36 Correct 4 ms 5212 KB Output is correct
37 Correct 2 ms 5212 KB Output is correct
38 Correct 3 ms 5212 KB Output is correct
39 Correct 3 ms 5208 KB Output is correct
40 Correct 3 ms 5212 KB Output is correct
41 Correct 3 ms 5212 KB Output is correct
42 Correct 2 ms 5212 KB Output is correct
43 Correct 2 ms 5212 KB Output is correct
44 Correct 2 ms 5212 KB Output is correct
45 Correct 3 ms 5464 KB Output is correct
46 Correct 3 ms 5212 KB Output is correct
47 Correct 3 ms 5212 KB Output is correct
48 Correct 2 ms 5180 KB Output is correct
49 Correct 3 ms 5212 KB Output is correct
50 Correct 3 ms 5212 KB Output is correct
51 Correct 3 ms 5212 KB Output is correct
52 Correct 3 ms 5212 KB Output is correct
53 Correct 4 ms 5376 KB Output is correct
54 Correct 3 ms 5208 KB Output is correct
55 Correct 2 ms 5212 KB Output is correct
56 Correct 2 ms 5212 KB Output is correct
57 Correct 2 ms 5212 KB Output is correct
58 Correct 3 ms 5212 KB Output is correct
59 Correct 4 ms 5212 KB Output is correct
60 Correct 2 ms 5212 KB Output is correct
61 Correct 3 ms 5208 KB Output is correct
62 Correct 4 ms 5212 KB Output is correct
63 Correct 2 ms 5212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 3 ms 4952 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 3 ms 5160 KB Output is correct
5 Correct 2 ms 4952 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 3 ms 4956 KB Output is correct
9 Correct 3 ms 4956 KB Output is correct
10 Correct 3 ms 4952 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 5160 KB Output is correct
13 Correct 3 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 3 ms 4956 KB Output is correct
16 Correct 2 ms 4952 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 2 ms 5020 KB Output is correct
19 Correct 2 ms 4952 KB Output is correct
20 Correct 3 ms 4956 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 3 ms 5172 KB Output is correct
23 Correct 2 ms 5212 KB Output is correct
24 Correct 4 ms 5212 KB Output is correct
25 Correct 4 ms 5212 KB Output is correct
26 Correct 3 ms 5212 KB Output is correct
27 Correct 4 ms 5356 KB Output is correct
28 Correct 2 ms 5212 KB Output is correct
29 Correct 2 ms 5212 KB Output is correct
30 Correct 3 ms 5212 KB Output is correct
31 Correct 3 ms 5244 KB Output is correct
32 Correct 2 ms 5212 KB Output is correct
33 Correct 3 ms 5208 KB Output is correct
34 Correct 3 ms 5208 KB Output is correct
35 Correct 2 ms 5212 KB Output is correct
36 Correct 4 ms 5212 KB Output is correct
37 Correct 2 ms 5212 KB Output is correct
38 Correct 3 ms 5212 KB Output is correct
39 Correct 3 ms 5208 KB Output is correct
40 Correct 3 ms 5212 KB Output is correct
41 Correct 3 ms 5212 KB Output is correct
42 Correct 2 ms 5212 KB Output is correct
43 Correct 2 ms 5212 KB Output is correct
44 Correct 2 ms 5212 KB Output is correct
45 Correct 3 ms 5464 KB Output is correct
46 Correct 3 ms 5212 KB Output is correct
47 Correct 3 ms 5212 KB Output is correct
48 Correct 2 ms 5180 KB Output is correct
49 Correct 3 ms 5212 KB Output is correct
50 Correct 3 ms 5212 KB Output is correct
51 Correct 3 ms 5212 KB Output is correct
52 Correct 3 ms 5212 KB Output is correct
53 Correct 4 ms 5376 KB Output is correct
54 Correct 3 ms 5208 KB Output is correct
55 Correct 2 ms 5212 KB Output is correct
56 Correct 2 ms 5212 KB Output is correct
57 Correct 2 ms 5212 KB Output is correct
58 Correct 3 ms 5212 KB Output is correct
59 Correct 4 ms 5212 KB Output is correct
60 Correct 2 ms 5212 KB Output is correct
61 Correct 3 ms 5208 KB Output is correct
62 Correct 4 ms 5212 KB Output is correct
63 Correct 2 ms 5212 KB Output is correct
64 Correct 74 ms 14192 KB Output is correct
65 Correct 70 ms 14184 KB Output is correct
66 Correct 58 ms 14416 KB Output is correct
67 Correct 55 ms 14416 KB Output is correct
68 Correct 109 ms 14312 KB Output is correct
69 Correct 80 ms 14420 KB Output is correct
70 Correct 54 ms 14360 KB Output is correct
71 Correct 52 ms 14460 KB Output is correct
72 Correct 84 ms 14412 KB Output is correct
73 Correct 63 ms 26960 KB Output is correct
74 Correct 84 ms 26864 KB Output is correct
75 Correct 65 ms 14160 KB Output is correct
76 Correct 67 ms 14160 KB Output is correct
77 Correct 55 ms 14160 KB Output is correct
78 Correct 60 ms 14164 KB Output is correct
79 Correct 53 ms 14164 KB Output is correct
80 Correct 72 ms 14164 KB Output is correct
81 Correct 74 ms 14424 KB Output is correct
82 Correct 59 ms 14484 KB Output is correct
83 Correct 89 ms 19496 KB Output is correct
84 Correct 80 ms 21588 KB Output is correct
85 Correct 78 ms 21328 KB Output is correct
86 Correct 52 ms 15700 KB Output is correct
87 Correct 55 ms 14936 KB Output is correct
88 Correct 79 ms 15444 KB Output is correct
89 Correct 60 ms 15444 KB Output is correct
90 Correct 61 ms 15292 KB Output is correct
91 Correct 83 ms 15600 KB Output is correct
92 Correct 60 ms 15968 KB Output is correct
93 Correct 67 ms 18192 KB Output is correct
94 Correct 60 ms 19912 KB Output is correct
95 Correct 64 ms 18584 KB Output is correct
96 Correct 86 ms 16972 KB Output is correct
97 Correct 67 ms 15464 KB Output is correct
98 Correct 67 ms 14928 KB Output is correct
99 Correct 79 ms 14676 KB Output is correct
100 Correct 87 ms 17780 KB Output is correct
101 Correct 74 ms 15852 KB Output is correct
102 Correct 65 ms 14960 KB Output is correct
103 Correct 67 ms 14928 KB Output is correct
104 Correct 53 ms 15164 KB Output is correct
105 Correct 84 ms 23740 KB Output is correct
106 Correct 47 ms 14924 KB Output is correct
107 Correct 40 ms 14796 KB Output is correct
108 Correct 103 ms 27732 KB Output is correct
109 Correct 63 ms 15016 KB Output is correct
110 Correct 99 ms 27988 KB Output is correct
111 Correct 92 ms 14276 KB Output is correct