# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
899024 | 2024-01-05T11:01:29 Z | penguin133 | Power Plant (JOI20_power) | C++17 | 184 ms | 24192 KB |
#include <bits/stdc++.h> using namespace std; #define int long long int dp[200005],ans; char A[200005]; vector<int>v[200005]; void dfs(int p, int x){ for(int i=0;i<v[p].size();i++)if(v[p][i] - x)dfs(v[p][i], p); if(A[p] - '0'){ for(int i=0;i<v[p].size();i++)if(v[p][i] - x)dp[p] += dp[v[p][i]], ans = max(ans, dp[v[p][i]] + 1); dp[p]--; dp[p] = max(1ll, dp[p]); } else for(int i=0;i<v[p].size();i++)if(v[p][i] - x)dp[p] += dp[v[p][i]]; } main(){ int n;cin >> n; for(int i=1;i<n;i++){ int a,b; cin >> a >> b; v[a].push_back(b); v[b].push_back(a); } for(int i=1;i<=n;i++)cin >> A[i]; dfs(1, -1); for(int i=1;i<=n;i++)ans = max(ans, dp[i]); cout << ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 6748 KB | Output is correct |
2 | Correct | 1 ms | 6744 KB | Output is correct |
3 | Correct | 2 ms | 6748 KB | Output is correct |
4 | Correct | 1 ms | 6748 KB | Output is correct |
5 | Correct | 1 ms | 6748 KB | Output is correct |
6 | Correct | 2 ms | 6744 KB | Output is correct |
7 | Correct | 2 ms | 6748 KB | Output is correct |
8 | Correct | 2 ms | 7412 KB | Output is correct |
9 | Correct | 1 ms | 6748 KB | Output is correct |
10 | Correct | 1 ms | 6748 KB | Output is correct |
11 | Correct | 1 ms | 6748 KB | Output is correct |
12 | Correct | 1 ms | 6748 KB | Output is correct |
13 | Correct | 2 ms | 6780 KB | Output is correct |
14 | Correct | 1 ms | 6748 KB | Output is correct |
15 | Correct | 1 ms | 6748 KB | Output is correct |
16 | Correct | 1 ms | 6748 KB | Output is correct |
17 | Correct | 2 ms | 6748 KB | Output is correct |
18 | Correct | 1 ms | 6748 KB | Output is correct |
19 | Correct | 2 ms | 6748 KB | Output is correct |
20 | Correct | 2 ms | 6744 KB | Output is correct |
21 | Correct | 1 ms | 6748 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 6748 KB | Output is correct |
2 | Correct | 1 ms | 6744 KB | Output is correct |
3 | Correct | 2 ms | 6748 KB | Output is correct |
4 | Correct | 1 ms | 6748 KB | Output is correct |
5 | Correct | 1 ms | 6748 KB | Output is correct |
6 | Correct | 2 ms | 6744 KB | Output is correct |
7 | Correct | 2 ms | 6748 KB | Output is correct |
8 | Correct | 2 ms | 7412 KB | Output is correct |
9 | Correct | 1 ms | 6748 KB | Output is correct |
10 | Correct | 1 ms | 6748 KB | Output is correct |
11 | Correct | 1 ms | 6748 KB | Output is correct |
12 | Correct | 1 ms | 6748 KB | Output is correct |
13 | Correct | 2 ms | 6780 KB | Output is correct |
14 | Correct | 1 ms | 6748 KB | Output is correct |
15 | Correct | 1 ms | 6748 KB | Output is correct |
16 | Correct | 1 ms | 6748 KB | Output is correct |
17 | Correct | 2 ms | 6748 KB | Output is correct |
18 | Correct | 1 ms | 6748 KB | Output is correct |
19 | Correct | 2 ms | 6748 KB | Output is correct |
20 | Correct | 2 ms | 6744 KB | Output is correct |
21 | Correct | 1 ms | 6748 KB | Output is correct |
22 | Correct | 3 ms | 6748 KB | Output is correct |
23 | Correct | 2 ms | 6804 KB | Output is correct |
24 | Correct | 2 ms | 6748 KB | Output is correct |
25 | Correct | 4 ms | 7000 KB | Output is correct |
26 | Correct | 3 ms | 6796 KB | Output is correct |
27 | Correct | 2 ms | 6748 KB | Output is correct |
28 | Correct | 2 ms | 6832 KB | Output is correct |
29 | Correct | 2 ms | 6744 KB | Output is correct |
30 | Correct | 2 ms | 6748 KB | Output is correct |
31 | Correct | 2 ms | 6748 KB | Output is correct |
32 | Correct | 2 ms | 6788 KB | Output is correct |
33 | Correct | 3 ms | 6748 KB | Output is correct |
34 | Correct | 2 ms | 6748 KB | Output is correct |
35 | Correct | 3 ms | 6768 KB | Output is correct |
36 | Correct | 2 ms | 6744 KB | Output is correct |
37 | Correct | 2 ms | 6748 KB | Output is correct |
38 | Correct | 2 ms | 6748 KB | Output is correct |
39 | Correct | 2 ms | 6748 KB | Output is correct |
40 | Correct | 2 ms | 6748 KB | Output is correct |
41 | Correct | 2 ms | 6748 KB | Output is correct |
42 | Correct | 2 ms | 6748 KB | Output is correct |
43 | Correct | 2 ms | 6748 KB | Output is correct |
44 | Correct | 2 ms | 6796 KB | Output is correct |
45 | Correct | 2 ms | 6748 KB | Output is correct |
46 | Correct | 2 ms | 6748 KB | Output is correct |
47 | Correct | 2 ms | 6748 KB | Output is correct |
48 | Correct | 2 ms | 6748 KB | Output is correct |
49 | Correct | 2 ms | 6748 KB | Output is correct |
50 | Correct | 3 ms | 6748 KB | Output is correct |
51 | Correct | 2 ms | 6748 KB | Output is correct |
52 | Correct | 2 ms | 6748 KB | Output is correct |
53 | Correct | 3 ms | 6748 KB | Output is correct |
54 | Correct | 4 ms | 6900 KB | Output is correct |
55 | Correct | 2 ms | 6748 KB | Output is correct |
56 | Correct | 3 ms | 6748 KB | Output is correct |
57 | Correct | 2 ms | 6748 KB | Output is correct |
58 | Correct | 2 ms | 6748 KB | Output is correct |
59 | Correct | 2 ms | 6748 KB | Output is correct |
60 | Correct | 2 ms | 6748 KB | Output is correct |
61 | Correct | 2 ms | 6748 KB | Output is correct |
62 | Correct | 2 ms | 6748 KB | Output is correct |
63 | Correct | 2 ms | 6748 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 6748 KB | Output is correct |
2 | Correct | 1 ms | 6744 KB | Output is correct |
3 | Correct | 2 ms | 6748 KB | Output is correct |
4 | Correct | 1 ms | 6748 KB | Output is correct |
5 | Correct | 1 ms | 6748 KB | Output is correct |
6 | Correct | 2 ms | 6744 KB | Output is correct |
7 | Correct | 2 ms | 6748 KB | Output is correct |
8 | Correct | 2 ms | 7412 KB | Output is correct |
9 | Correct | 1 ms | 6748 KB | Output is correct |
10 | Correct | 1 ms | 6748 KB | Output is correct |
11 | Correct | 1 ms | 6748 KB | Output is correct |
12 | Correct | 1 ms | 6748 KB | Output is correct |
13 | Correct | 2 ms | 6780 KB | Output is correct |
14 | Correct | 1 ms | 6748 KB | Output is correct |
15 | Correct | 1 ms | 6748 KB | Output is correct |
16 | Correct | 1 ms | 6748 KB | Output is correct |
17 | Correct | 2 ms | 6748 KB | Output is correct |
18 | Correct | 1 ms | 6748 KB | Output is correct |
19 | Correct | 2 ms | 6748 KB | Output is correct |
20 | Correct | 2 ms | 6744 KB | Output is correct |
21 | Correct | 1 ms | 6748 KB | Output is correct |
22 | Correct | 3 ms | 6748 KB | Output is correct |
23 | Correct | 2 ms | 6804 KB | Output is correct |
24 | Correct | 2 ms | 6748 KB | Output is correct |
25 | Correct | 4 ms | 7000 KB | Output is correct |
26 | Correct | 3 ms | 6796 KB | Output is correct |
27 | Correct | 2 ms | 6748 KB | Output is correct |
28 | Correct | 2 ms | 6832 KB | Output is correct |
29 | Correct | 2 ms | 6744 KB | Output is correct |
30 | Correct | 2 ms | 6748 KB | Output is correct |
31 | Correct | 2 ms | 6748 KB | Output is correct |
32 | Correct | 2 ms | 6788 KB | Output is correct |
33 | Correct | 3 ms | 6748 KB | Output is correct |
34 | Correct | 2 ms | 6748 KB | Output is correct |
35 | Correct | 3 ms | 6768 KB | Output is correct |
36 | Correct | 2 ms | 6744 KB | Output is correct |
37 | Correct | 2 ms | 6748 KB | Output is correct |
38 | Correct | 2 ms | 6748 KB | Output is correct |
39 | Correct | 2 ms | 6748 KB | Output is correct |
40 | Correct | 2 ms | 6748 KB | Output is correct |
41 | Correct | 2 ms | 6748 KB | Output is correct |
42 | Correct | 2 ms | 6748 KB | Output is correct |
43 | Correct | 2 ms | 6748 KB | Output is correct |
44 | Correct | 2 ms | 6796 KB | Output is correct |
45 | Correct | 2 ms | 6748 KB | Output is correct |
46 | Correct | 2 ms | 6748 KB | Output is correct |
47 | Correct | 2 ms | 6748 KB | Output is correct |
48 | Correct | 2 ms | 6748 KB | Output is correct |
49 | Correct | 2 ms | 6748 KB | Output is correct |
50 | Correct | 3 ms | 6748 KB | Output is correct |
51 | Correct | 2 ms | 6748 KB | Output is correct |
52 | Correct | 2 ms | 6748 KB | Output is correct |
53 | Correct | 3 ms | 6748 KB | Output is correct |
54 | Correct | 4 ms | 6900 KB | Output is correct |
55 | Correct | 2 ms | 6748 KB | Output is correct |
56 | Correct | 3 ms | 6748 KB | Output is correct |
57 | Correct | 2 ms | 6748 KB | Output is correct |
58 | Correct | 2 ms | 6748 KB | Output is correct |
59 | Correct | 2 ms | 6748 KB | Output is correct |
60 | Correct | 2 ms | 6748 KB | Output is correct |
61 | Correct | 2 ms | 6748 KB | Output is correct |
62 | Correct | 2 ms | 6748 KB | Output is correct |
63 | Correct | 2 ms | 6748 KB | Output is correct |
64 | Correct | 160 ms | 16800 KB | Output is correct |
65 | Correct | 137 ms | 16696 KB | Output is correct |
66 | Correct | 160 ms | 16804 KB | Output is correct |
67 | Correct | 148 ms | 16936 KB | Output is correct |
68 | Correct | 137 ms | 17056 KB | Output is correct |
69 | Correct | 131 ms | 16724 KB | Output is correct |
70 | Correct | 124 ms | 16720 KB | Output is correct |
71 | Correct | 145 ms | 16724 KB | Output is correct |
72 | Correct | 168 ms | 16732 KB | Output is correct |
73 | Correct | 154 ms | 23400 KB | Output is correct |
74 | Correct | 130 ms | 23380 KB | Output is correct |
75 | Correct | 129 ms | 18052 KB | Output is correct |
76 | Correct | 163 ms | 18192 KB | Output is correct |
77 | Correct | 158 ms | 16924 KB | Output is correct |
78 | Correct | 123 ms | 16684 KB | Output is correct |
79 | Correct | 169 ms | 16944 KB | Output is correct |
80 | Correct | 159 ms | 16856 KB | Output is correct |
81 | Correct | 134 ms | 16924 KB | Output is correct |
82 | Correct | 142 ms | 16716 KB | Output is correct |
83 | Correct | 162 ms | 19980 KB | Output is correct |
84 | Correct | 133 ms | 21076 KB | Output is correct |
85 | Correct | 184 ms | 21108 KB | Output is correct |
86 | Correct | 138 ms | 17528 KB | Output is correct |
87 | Correct | 126 ms | 17256 KB | Output is correct |
88 | Correct | 157 ms | 17472 KB | Output is correct |
89 | Correct | 156 ms | 17332 KB | Output is correct |
90 | Correct | 140 ms | 17440 KB | Output is correct |
91 | Correct | 145 ms | 17512 KB | Output is correct |
92 | Correct | 150 ms | 17628 KB | Output is correct |
93 | Correct | 131 ms | 18628 KB | Output is correct |
94 | Correct | 134 ms | 19648 KB | Output is correct |
95 | Correct | 126 ms | 18864 KB | Output is correct |
96 | Correct | 133 ms | 18048 KB | Output is correct |
97 | Correct | 156 ms | 17152 KB | Output is correct |
98 | Correct | 125 ms | 16980 KB | Output is correct |
99 | Correct | 142 ms | 16924 KB | Output is correct |
100 | Correct | 144 ms | 18740 KB | Output is correct |
101 | Correct | 126 ms | 17360 KB | Output is correct |
102 | Correct | 147 ms | 16912 KB | Output is correct |
103 | Correct | 135 ms | 16980 KB | Output is correct |
104 | Correct | 124 ms | 17344 KB | Output is correct |
105 | Correct | 148 ms | 21584 KB | Output is correct |
106 | Correct | 116 ms | 17232 KB | Output is correct |
107 | Correct | 101 ms | 17348 KB | Output is correct |
108 | Correct | 155 ms | 24192 KB | Output is correct |
109 | Correct | 123 ms | 17292 KB | Output is correct |
110 | Correct | 146 ms | 23892 KB | Output is correct |
111 | Correct | 122 ms | 16840 KB | Output is correct |