Submission #1019872

# Submission time Handle Problem Language Result Execution time Memory
1019872 2024-07-11T10:08:42 Z Andrey Power Plant (JOI20_power) C++14
100 / 100
87 ms 29268 KB
#include<bits/stdc++.h>
using namespace std;

vector<int> haha[200001];
vector<int> dp(200001);
vector<int> col(200001);
int ans = 0;

void dfs(int a, int t) {
    int sb = 0;
    for(int v: haha[a]) {
        if(v != t) {
            dfs(v,a);
            sb+=dp[v];
        }
    }
    sb-=col[a];
    dp[a] = max(col[a],sb);
}

void dude(int a, int t, int u) {
    int big = u,sb = u-col[a];
    for(int v: haha[a]) {
        if(v != t) {
            big = max(big,dp[v]);
            sb+=dp[v];
        }
    }
    if(col[a]) {
        ans = max(ans,big+1);
    }
    for(int v: haha[a]) {
        if(v != t) {
            dude(v,a,max(col[a],sb-dp[v]));
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,a,b;
    cin >> n;
    for(int i = 0; i < n-1; i++) {
        cin >> a >> b;
        haha[a].push_back(b);
        haha[b].push_back(a);
    }
    for(int i = 1; i <= n; i++) {
        char a;
        cin >> a;
        if(a == '1') {
            col[i] = 1;
        }
    }
    dfs(1,-1);
    dude(1,-1,0);
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6492 KB Output is correct
2 Correct 3 ms 6732 KB Output is correct
3 Correct 3 ms 6492 KB Output is correct
4 Correct 4 ms 6492 KB Output is correct
5 Correct 3 ms 6492 KB Output is correct
6 Correct 3 ms 6492 KB Output is correct
7 Correct 3 ms 6492 KB Output is correct
8 Correct 3 ms 6492 KB Output is correct
9 Correct 3 ms 6740 KB Output is correct
10 Correct 3 ms 6492 KB Output is correct
11 Correct 3 ms 6488 KB Output is correct
12 Correct 3 ms 6492 KB Output is correct
13 Correct 3 ms 6492 KB Output is correct
14 Correct 3 ms 6492 KB Output is correct
15 Correct 3 ms 6640 KB Output is correct
16 Correct 2 ms 6744 KB Output is correct
17 Correct 3 ms 6492 KB Output is correct
18 Correct 3 ms 6492 KB Output is correct
19 Correct 3 ms 6492 KB Output is correct
20 Correct 3 ms 6496 KB Output is correct
21 Correct 3 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6492 KB Output is correct
2 Correct 3 ms 6732 KB Output is correct
3 Correct 3 ms 6492 KB Output is correct
4 Correct 4 ms 6492 KB Output is correct
5 Correct 3 ms 6492 KB Output is correct
6 Correct 3 ms 6492 KB Output is correct
7 Correct 3 ms 6492 KB Output is correct
8 Correct 3 ms 6492 KB Output is correct
9 Correct 3 ms 6740 KB Output is correct
10 Correct 3 ms 6492 KB Output is correct
11 Correct 3 ms 6488 KB Output is correct
12 Correct 3 ms 6492 KB Output is correct
13 Correct 3 ms 6492 KB Output is correct
14 Correct 3 ms 6492 KB Output is correct
15 Correct 3 ms 6640 KB Output is correct
16 Correct 2 ms 6744 KB Output is correct
17 Correct 3 ms 6492 KB Output is correct
18 Correct 3 ms 6492 KB Output is correct
19 Correct 3 ms 6492 KB Output is correct
20 Correct 3 ms 6496 KB Output is correct
21 Correct 3 ms 6492 KB Output is correct
22 Correct 3 ms 6748 KB Output is correct
23 Correct 3 ms 6776 KB Output is correct
24 Correct 3 ms 6748 KB Output is correct
25 Correct 3 ms 6748 KB Output is correct
26 Correct 3 ms 6692 KB Output is correct
27 Correct 4 ms 6752 KB Output is correct
28 Correct 4 ms 6756 KB Output is correct
29 Correct 3 ms 6748 KB Output is correct
30 Correct 3 ms 6748 KB Output is correct
31 Correct 3 ms 6752 KB Output is correct
32 Correct 3 ms 6748 KB Output is correct
33 Correct 3 ms 6748 KB Output is correct
34 Correct 3 ms 6620 KB Output is correct
35 Correct 3 ms 6748 KB Output is correct
36 Correct 3 ms 6748 KB Output is correct
37 Correct 3 ms 6748 KB Output is correct
38 Correct 3 ms 6748 KB Output is correct
39 Correct 3 ms 6792 KB Output is correct
40 Correct 3 ms 6748 KB Output is correct
41 Correct 3 ms 6748 KB Output is correct
42 Correct 3 ms 6748 KB Output is correct
43 Correct 5 ms 7004 KB Output is correct
44 Correct 4 ms 6748 KB Output is correct
45 Correct 3 ms 6748 KB Output is correct
46 Correct 3 ms 6748 KB Output is correct
47 Correct 4 ms 6608 KB Output is correct
48 Correct 3 ms 6748 KB Output is correct
49 Correct 3 ms 6748 KB Output is correct
50 Correct 3 ms 7000 KB Output is correct
51 Correct 3 ms 6748 KB Output is correct
52 Correct 3 ms 6748 KB Output is correct
53 Correct 3 ms 6748 KB Output is correct
54 Correct 3 ms 6748 KB Output is correct
55 Correct 3 ms 6748 KB Output is correct
56 Correct 3 ms 6748 KB Output is correct
57 Correct 3 ms 6748 KB Output is correct
58 Correct 3 ms 6748 KB Output is correct
59 Correct 3 ms 6764 KB Output is correct
60 Correct 3 ms 6748 KB Output is correct
61 Correct 3 ms 6748 KB Output is correct
62 Correct 3 ms 6748 KB Output is correct
63 Correct 3 ms 6808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6492 KB Output is correct
2 Correct 3 ms 6732 KB Output is correct
3 Correct 3 ms 6492 KB Output is correct
4 Correct 4 ms 6492 KB Output is correct
5 Correct 3 ms 6492 KB Output is correct
6 Correct 3 ms 6492 KB Output is correct
7 Correct 3 ms 6492 KB Output is correct
8 Correct 3 ms 6492 KB Output is correct
9 Correct 3 ms 6740 KB Output is correct
10 Correct 3 ms 6492 KB Output is correct
11 Correct 3 ms 6488 KB Output is correct
12 Correct 3 ms 6492 KB Output is correct
13 Correct 3 ms 6492 KB Output is correct
14 Correct 3 ms 6492 KB Output is correct
15 Correct 3 ms 6640 KB Output is correct
16 Correct 2 ms 6744 KB Output is correct
17 Correct 3 ms 6492 KB Output is correct
18 Correct 3 ms 6492 KB Output is correct
19 Correct 3 ms 6492 KB Output is correct
20 Correct 3 ms 6496 KB Output is correct
21 Correct 3 ms 6492 KB Output is correct
22 Correct 3 ms 6748 KB Output is correct
23 Correct 3 ms 6776 KB Output is correct
24 Correct 3 ms 6748 KB Output is correct
25 Correct 3 ms 6748 KB Output is correct
26 Correct 3 ms 6692 KB Output is correct
27 Correct 4 ms 6752 KB Output is correct
28 Correct 4 ms 6756 KB Output is correct
29 Correct 3 ms 6748 KB Output is correct
30 Correct 3 ms 6748 KB Output is correct
31 Correct 3 ms 6752 KB Output is correct
32 Correct 3 ms 6748 KB Output is correct
33 Correct 3 ms 6748 KB Output is correct
34 Correct 3 ms 6620 KB Output is correct
35 Correct 3 ms 6748 KB Output is correct
36 Correct 3 ms 6748 KB Output is correct
37 Correct 3 ms 6748 KB Output is correct
38 Correct 3 ms 6748 KB Output is correct
39 Correct 3 ms 6792 KB Output is correct
40 Correct 3 ms 6748 KB Output is correct
41 Correct 3 ms 6748 KB Output is correct
42 Correct 3 ms 6748 KB Output is correct
43 Correct 5 ms 7004 KB Output is correct
44 Correct 4 ms 6748 KB Output is correct
45 Correct 3 ms 6748 KB Output is correct
46 Correct 3 ms 6748 KB Output is correct
47 Correct 4 ms 6608 KB Output is correct
48 Correct 3 ms 6748 KB Output is correct
49 Correct 3 ms 6748 KB Output is correct
50 Correct 3 ms 7000 KB Output is correct
51 Correct 3 ms 6748 KB Output is correct
52 Correct 3 ms 6748 KB Output is correct
53 Correct 3 ms 6748 KB Output is correct
54 Correct 3 ms 6748 KB Output is correct
55 Correct 3 ms 6748 KB Output is correct
56 Correct 3 ms 6748 KB Output is correct
57 Correct 3 ms 6748 KB Output is correct
58 Correct 3 ms 6748 KB Output is correct
59 Correct 3 ms 6764 KB Output is correct
60 Correct 3 ms 6748 KB Output is correct
61 Correct 3 ms 6748 KB Output is correct
62 Correct 3 ms 6748 KB Output is correct
63 Correct 3 ms 6808 KB Output is correct
64 Correct 71 ms 15700 KB Output is correct
65 Correct 76 ms 15700 KB Output is correct
66 Correct 68 ms 15672 KB Output is correct
67 Correct 77 ms 15696 KB Output is correct
68 Correct 69 ms 15704 KB Output is correct
69 Correct 68 ms 15696 KB Output is correct
70 Correct 71 ms 15696 KB Output is correct
71 Correct 69 ms 15636 KB Output is correct
72 Correct 70 ms 15700 KB Output is correct
73 Correct 87 ms 28240 KB Output is correct
74 Correct 87 ms 28288 KB Output is correct
75 Correct 65 ms 15696 KB Output is correct
76 Correct 70 ms 15696 KB Output is correct
77 Correct 75 ms 15576 KB Output is correct
78 Correct 72 ms 15700 KB Output is correct
79 Correct 71 ms 15700 KB Output is correct
80 Correct 68 ms 15648 KB Output is correct
81 Correct 62 ms 15888 KB Output is correct
82 Correct 68 ms 15824 KB Output is correct
83 Correct 76 ms 20916 KB Output is correct
84 Correct 82 ms 23052 KB Output is correct
85 Correct 82 ms 22612 KB Output is correct
86 Correct 70 ms 17048 KB Output is correct
87 Correct 68 ms 16468 KB Output is correct
88 Correct 69 ms 16976 KB Output is correct
89 Correct 70 ms 16964 KB Output is correct
90 Correct 73 ms 16720 KB Output is correct
91 Correct 71 ms 16980 KB Output is correct
92 Correct 73 ms 17236 KB Output is correct
93 Correct 66 ms 19664 KB Output is correct
94 Correct 73 ms 21196 KB Output is correct
95 Correct 72 ms 19972 KB Output is correct
96 Correct 64 ms 18260 KB Output is correct
97 Correct 67 ms 16668 KB Output is correct
98 Correct 67 ms 16208 KB Output is correct
99 Correct 70 ms 16144 KB Output is correct
100 Correct 75 ms 19276 KB Output is correct
101 Correct 72 ms 17232 KB Output is correct
102 Correct 62 ms 16468 KB Output is correct
103 Correct 64 ms 16212 KB Output is correct
104 Correct 42 ms 16592 KB Output is correct
105 Correct 80 ms 25012 KB Output is correct
106 Correct 42 ms 16328 KB Output is correct
107 Correct 41 ms 16284 KB Output is correct
108 Correct 83 ms 29012 KB Output is correct
109 Correct 47 ms 16580 KB Output is correct
110 Correct 85 ms 29268 KB Output is correct
111 Correct 58 ms 15632 KB Output is correct