Submission #528247

# Submission time Handle Problem Language Result Execution time Memory
528247 2022-02-19T18:17:16 Z ajpiano Power Plant (JOI20_power) C++17
100 / 100
156 ms 31308 KB
#include <bits/stdc++.h>

using namespace std;

#define f first
#define s second

typedef long long ll;
typedef pair<int,int> pi;

const int large = 2e5+5;

int n, ans = 0;
vector<bool> power;
vector<int> edges[large];

vector<int> dp;

void dfs(int node, int par){
    int cans = 0;
    if(power[node]) cans = 1;
    int best = 0;
    int csum = 0;
    for(auto &a: edges[node]){
        if(a == par) continue;
        dfs(a,node);
        csum += dp[a];
        best = max(best,dp[a]);
    }
    if(power[node]){
        ans = max(ans,best+1);
        csum--;
    }
    cans = max(cans,csum);
    ans = max(ans,cans);
    dp[node] = cans;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    dp.resize(n+1); power.resize(n+1);
    for(int i = 0; i < n-1; i++){
        int u,v; cin >> u >> v;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }
    for(int i = 1; i <= n; i++){
        char a; cin >> a;
        if(a == '1') power[i] = 1;
    }
    dfs(1,0);
    cout << ans << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5012 KB Output is correct
2 Correct 4 ms 5008 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 4 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 4 ms 5008 KB Output is correct
10 Correct 2 ms 4940 KB Output is correct
11 Correct 3 ms 5016 KB Output is correct
12 Correct 4 ms 5008 KB Output is correct
13 Correct 4 ms 4940 KB Output is correct
14 Correct 4 ms 5012 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 2 ms 4940 KB Output is correct
21 Correct 3 ms 4912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5012 KB Output is correct
2 Correct 4 ms 5008 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 4 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 4 ms 5008 KB Output is correct
10 Correct 2 ms 4940 KB Output is correct
11 Correct 3 ms 5016 KB Output is correct
12 Correct 4 ms 5008 KB Output is correct
13 Correct 4 ms 4940 KB Output is correct
14 Correct 4 ms 5012 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 2 ms 4940 KB Output is correct
21 Correct 3 ms 4912 KB Output is correct
22 Correct 3 ms 5068 KB Output is correct
23 Correct 4 ms 5068 KB Output is correct
24 Correct 4 ms 5024 KB Output is correct
25 Correct 5 ms 5068 KB Output is correct
26 Correct 3 ms 5068 KB Output is correct
27 Correct 3 ms 5020 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 5196 KB Output is correct
31 Correct 3 ms 5024 KB Output is correct
32 Correct 3 ms 5024 KB Output is correct
33 Correct 4 ms 5068 KB Output is correct
34 Correct 3 ms 5024 KB Output is correct
35 Correct 3 ms 5084 KB Output is correct
36 Correct 4 ms 5020 KB Output is correct
37 Correct 3 ms 5068 KB Output is correct
38 Correct 3 ms 5068 KB Output is correct
39 Correct 3 ms 5068 KB Output is correct
40 Correct 3 ms 5148 KB Output is correct
41 Correct 3 ms 5152 KB Output is correct
42 Correct 3 ms 5068 KB Output is correct
43 Correct 4 ms 5024 KB Output is correct
44 Correct 4 ms 5152 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 5020 KB Output is correct
48 Correct 3 ms 5196 KB Output is correct
49 Correct 4 ms 5196 KB Output is correct
50 Correct 4 ms 5156 KB Output is correct
51 Correct 4 ms 5080 KB Output is correct
52 Correct 3 ms 5068 KB Output is correct
53 Correct 3 ms 5068 KB Output is correct
54 Correct 4 ms 5068 KB Output is correct
55 Correct 3 ms 5068 KB Output is correct
56 Correct 3 ms 5024 KB Output is correct
57 Correct 3 ms 5196 KB Output is correct
58 Correct 4 ms 5068 KB Output is correct
59 Correct 3 ms 5068 KB Output is correct
60 Correct 3 ms 5196 KB Output is correct
61 Correct 4 ms 5020 KB Output is correct
62 Correct 4 ms 5208 KB Output is correct
63 Correct 4 ms 5068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5012 KB Output is correct
2 Correct 4 ms 5008 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 4 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 4 ms 5008 KB Output is correct
10 Correct 2 ms 4940 KB Output is correct
11 Correct 3 ms 5016 KB Output is correct
12 Correct 4 ms 5008 KB Output is correct
13 Correct 4 ms 4940 KB Output is correct
14 Correct 4 ms 5012 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 2 ms 4940 KB Output is correct
21 Correct 3 ms 4912 KB Output is correct
22 Correct 3 ms 5068 KB Output is correct
23 Correct 4 ms 5068 KB Output is correct
24 Correct 4 ms 5024 KB Output is correct
25 Correct 5 ms 5068 KB Output is correct
26 Correct 3 ms 5068 KB Output is correct
27 Correct 3 ms 5020 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 5196 KB Output is correct
31 Correct 3 ms 5024 KB Output is correct
32 Correct 3 ms 5024 KB Output is correct
33 Correct 4 ms 5068 KB Output is correct
34 Correct 3 ms 5024 KB Output is correct
35 Correct 3 ms 5084 KB Output is correct
36 Correct 4 ms 5020 KB Output is correct
37 Correct 3 ms 5068 KB Output is correct
38 Correct 3 ms 5068 KB Output is correct
39 Correct 3 ms 5068 KB Output is correct
40 Correct 3 ms 5148 KB Output is correct
41 Correct 3 ms 5152 KB Output is correct
42 Correct 3 ms 5068 KB Output is correct
43 Correct 4 ms 5024 KB Output is correct
44 Correct 4 ms 5152 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 5020 KB Output is correct
48 Correct 3 ms 5196 KB Output is correct
49 Correct 4 ms 5196 KB Output is correct
50 Correct 4 ms 5156 KB Output is correct
51 Correct 4 ms 5080 KB Output is correct
52 Correct 3 ms 5068 KB Output is correct
53 Correct 3 ms 5068 KB Output is correct
54 Correct 4 ms 5068 KB Output is correct
55 Correct 3 ms 5068 KB Output is correct
56 Correct 3 ms 5024 KB Output is correct
57 Correct 3 ms 5196 KB Output is correct
58 Correct 4 ms 5068 KB Output is correct
59 Correct 3 ms 5068 KB Output is correct
60 Correct 3 ms 5196 KB Output is correct
61 Correct 4 ms 5020 KB Output is correct
62 Correct 4 ms 5208 KB Output is correct
63 Correct 4 ms 5068 KB Output is correct
64 Correct 115 ms 14804 KB Output is correct
65 Correct 153 ms 14912 KB Output is correct
66 Correct 125 ms 14860 KB Output is correct
67 Correct 132 ms 14856 KB Output is correct
68 Correct 130 ms 14804 KB Output is correct
69 Correct 110 ms 14916 KB Output is correct
70 Correct 129 ms 14812 KB Output is correct
71 Correct 121 ms 14808 KB Output is correct
72 Correct 138 ms 14916 KB Output is correct
73 Correct 156 ms 30068 KB Output is correct
74 Correct 123 ms 29892 KB Output is correct
75 Correct 116 ms 14780 KB Output is correct
76 Correct 134 ms 14708 KB Output is correct
77 Correct 135 ms 14680 KB Output is correct
78 Correct 113 ms 14748 KB Output is correct
79 Correct 150 ms 14848 KB Output is correct
80 Correct 119 ms 14756 KB Output is correct
81 Correct 93 ms 15188 KB Output is correct
82 Correct 106 ms 14952 KB Output is correct
83 Correct 155 ms 20940 KB Output is correct
84 Correct 125 ms 23580 KB Output is correct
85 Correct 122 ms 23108 KB Output is correct
86 Correct 117 ms 16468 KB Output is correct
87 Correct 112 ms 15764 KB Output is correct
88 Correct 110 ms 16196 KB Output is correct
89 Correct 106 ms 16204 KB Output is correct
90 Correct 123 ms 15960 KB Output is correct
91 Correct 107 ms 16184 KB Output is correct
92 Correct 104 ms 16704 KB Output is correct
93 Correct 130 ms 19640 KB Output is correct
94 Correct 104 ms 21592 KB Output is correct
95 Correct 97 ms 20064 KB Output is correct
96 Correct 100 ms 17864 KB Output is correct
97 Correct 95 ms 16072 KB Output is correct
98 Correct 101 ms 15460 KB Output is correct
99 Correct 101 ms 15200 KB Output is correct
100 Correct 104 ms 19024 KB Output is correct
101 Correct 104 ms 16624 KB Output is correct
102 Correct 109 ms 15804 KB Output is correct
103 Correct 104 ms 15480 KB Output is correct
104 Correct 64 ms 15624 KB Output is correct
105 Correct 122 ms 26160 KB Output is correct
106 Correct 67 ms 15424 KB Output is correct
107 Correct 67 ms 15496 KB Output is correct
108 Correct 122 ms 30868 KB Output is correct
109 Correct 63 ms 15640 KB Output is correct
110 Correct 137 ms 31308 KB Output is correct
111 Correct 97 ms 14720 KB Output is correct