# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1094136 | 2024-09-28T15:15:27 Z | thangdz2k7 | Power Plant (JOI20_power) | C++17 | 91 ms | 28880 KB |
// author : thembululquaUwU // 3.9.2024 #include <bits/stdc++.h> #define pb push_back #define fi first #define se second #define endl '\n' using namespace std; using ll = long long; using ii = pair <int, int>; using vi = vector <int>; const int N = 2e5 + 5; const int mod = 1e9 + 7; void maxl(auto &a, auto b) {a = max(a, b);} void minl(auto &a, auto b) {a = min(a, b);} int n, dp[N], ans = 0; string s; vi adj[N]; void dfs(int u = 1, int p = 0){ dp[u] = 0; int mx = 0; for (int v : adj[u]) if (v ^ p){ dfs(v, u); dp[u] += dp[v]; maxl(mx, dp[v]); } if (s[u] == '1') { dp[u] = max(1, dp[u] - 1); maxl(ans, mx + 1); } maxl(ans, dp[u]); } void solve(){ cin >> n; for (int i = 1, u, v; i < n; ++ i){ cin >> u >> v; adj[u].pb(v); adj[v].pb(u); } cin >> s; s = ' ' + s; dfs(); cout << ans; } int main(){ if (fopen("pqh.inp", "r")){ freopen("pqh.inp", "r", stdin); freopen("pqh.out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t --) solve(); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4956 KB | Output is correct |
2 | Correct | 2 ms | 5156 KB | Output is correct |
3 | Correct | 2 ms | 4956 KB | Output is correct |
4 | Correct | 2 ms | 5156 KB | Output is correct |
5 | Correct | 2 ms | 4956 KB | Output is correct |
6 | Correct | 3 ms | 4952 KB | Output is correct |
7 | Correct | 2 ms | 5040 KB | Output is correct |
8 | Correct | 2 ms | 4956 KB | Output is correct |
9 | Correct | 2 ms | 4956 KB | Output is correct |
10 | Correct | 2 ms | 4956 KB | Output is correct |
11 | Correct | 3 ms | 4956 KB | Output is correct |
12 | Correct | 2 ms | 5160 KB | Output is correct |
13 | Correct | 2 ms | 4956 KB | Output is correct |
14 | Correct | 3 ms | 4956 KB | Output is correct |
15 | Correct | 3 ms | 4956 KB | Output is correct |
16 | Correct | 2 ms | 4956 KB | Output is correct |
17 | Correct | 2 ms | 4952 KB | Output is correct |
18 | Correct | 3 ms | 4960 KB | Output is correct |
19 | Correct | 2 ms | 5208 KB | Output is correct |
20 | Correct | 2 ms | 4952 KB | Output is correct |
21 | Correct | 3 ms | 4960 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4956 KB | Output is correct |
2 | Correct | 2 ms | 5156 KB | Output is correct |
3 | Correct | 2 ms | 4956 KB | Output is correct |
4 | Correct | 2 ms | 5156 KB | Output is correct |
5 | Correct | 2 ms | 4956 KB | Output is correct |
6 | Correct | 3 ms | 4952 KB | Output is correct |
7 | Correct | 2 ms | 5040 KB | Output is correct |
8 | Correct | 2 ms | 4956 KB | Output is correct |
9 | Correct | 2 ms | 4956 KB | Output is correct |
10 | Correct | 2 ms | 4956 KB | Output is correct |
11 | Correct | 3 ms | 4956 KB | Output is correct |
12 | Correct | 2 ms | 5160 KB | Output is correct |
13 | Correct | 2 ms | 4956 KB | Output is correct |
14 | Correct | 3 ms | 4956 KB | Output is correct |
15 | Correct | 3 ms | 4956 KB | Output is correct |
16 | Correct | 2 ms | 4956 KB | Output is correct |
17 | Correct | 2 ms | 4952 KB | Output is correct |
18 | Correct | 3 ms | 4960 KB | Output is correct |
19 | Correct | 2 ms | 5208 KB | Output is correct |
20 | Correct | 2 ms | 4952 KB | Output is correct |
21 | Correct | 3 ms | 4960 KB | Output is correct |
22 | Correct | 3 ms | 5208 KB | Output is correct |
23 | Correct | 3 ms | 5208 KB | Output is correct |
24 | Correct | 3 ms | 5212 KB | Output is correct |
25 | Correct | 3 ms | 5216 KB | Output is correct |
26 | Correct | 2 ms | 5216 KB | Output is correct |
27 | Correct | 2 ms | 5212 KB | Output is correct |
28 | Correct | 2 ms | 5220 KB | Output is correct |
29 | Correct | 3 ms | 5216 KB | Output is correct |
30 | Correct | 3 ms | 5220 KB | Output is correct |
31 | Correct | 4 ms | 5220 KB | Output is correct |
32 | Correct | 2 ms | 5212 KB | Output is correct |
33 | Correct | 2 ms | 5220 KB | Output is correct |
34 | Correct | 3 ms | 5220 KB | Output is correct |
35 | Correct | 3 ms | 5252 KB | Output is correct |
36 | Correct | 3 ms | 5212 KB | Output is correct |
37 | Correct | 3 ms | 5212 KB | Output is correct |
38 | Correct | 2 ms | 5212 KB | Output is correct |
39 | Correct | 3 ms | 5472 KB | Output is correct |
40 | Correct | 3 ms | 5216 KB | Output is correct |
41 | Correct | 3 ms | 5208 KB | Output is correct |
42 | Correct | 2 ms | 5212 KB | Output is correct |
43 | Correct | 3 ms | 5212 KB | Output is correct |
44 | Correct | 2 ms | 5172 KB | Output is correct |
45 | Correct | 3 ms | 5212 KB | Output is correct |
46 | Correct | 3 ms | 5212 KB | Output is correct |
47 | Correct | 4 ms | 5284 KB | Output is correct |
48 | Correct | 3 ms | 5212 KB | Output is correct |
49 | Correct | 2 ms | 5212 KB | Output is correct |
50 | Correct | 2 ms | 5212 KB | Output is correct |
51 | Correct | 3 ms | 5212 KB | Output is correct |
52 | Correct | 3 ms | 5208 KB | Output is correct |
53 | Correct | 3 ms | 5212 KB | Output is correct |
54 | Correct | 3 ms | 5212 KB | Output is correct |
55 | Correct | 2 ms | 5212 KB | Output is correct |
56 | Correct | 2 ms | 5212 KB | Output is correct |
57 | Correct | 3 ms | 5212 KB | Output is correct |
58 | Correct | 2 ms | 5244 KB | Output is correct |
59 | Correct | 3 ms | 5212 KB | Output is correct |
60 | Correct | 2 ms | 5212 KB | Output is correct |
61 | Correct | 2 ms | 5196 KB | Output is correct |
62 | Correct | 3 ms | 5212 KB | Output is correct |
63 | Correct | 3 ms | 5212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4956 KB | Output is correct |
2 | Correct | 2 ms | 5156 KB | Output is correct |
3 | Correct | 2 ms | 4956 KB | Output is correct |
4 | Correct | 2 ms | 5156 KB | Output is correct |
5 | Correct | 2 ms | 4956 KB | Output is correct |
6 | Correct | 3 ms | 4952 KB | Output is correct |
7 | Correct | 2 ms | 5040 KB | Output is correct |
8 | Correct | 2 ms | 4956 KB | Output is correct |
9 | Correct | 2 ms | 4956 KB | Output is correct |
10 | Correct | 2 ms | 4956 KB | Output is correct |
11 | Correct | 3 ms | 4956 KB | Output is correct |
12 | Correct | 2 ms | 5160 KB | Output is correct |
13 | Correct | 2 ms | 4956 KB | Output is correct |
14 | Correct | 3 ms | 4956 KB | Output is correct |
15 | Correct | 3 ms | 4956 KB | Output is correct |
16 | Correct | 2 ms | 4956 KB | Output is correct |
17 | Correct | 2 ms | 4952 KB | Output is correct |
18 | Correct | 3 ms | 4960 KB | Output is correct |
19 | Correct | 2 ms | 5208 KB | Output is correct |
20 | Correct | 2 ms | 4952 KB | Output is correct |
21 | Correct | 3 ms | 4960 KB | Output is correct |
22 | Correct | 3 ms | 5208 KB | Output is correct |
23 | Correct | 3 ms | 5208 KB | Output is correct |
24 | Correct | 3 ms | 5212 KB | Output is correct |
25 | Correct | 3 ms | 5216 KB | Output is correct |
26 | Correct | 2 ms | 5216 KB | Output is correct |
27 | Correct | 2 ms | 5212 KB | Output is correct |
28 | Correct | 2 ms | 5220 KB | Output is correct |
29 | Correct | 3 ms | 5216 KB | Output is correct |
30 | Correct | 3 ms | 5220 KB | Output is correct |
31 | Correct | 4 ms | 5220 KB | Output is correct |
32 | Correct | 2 ms | 5212 KB | Output is correct |
33 | Correct | 2 ms | 5220 KB | Output is correct |
34 | Correct | 3 ms | 5220 KB | Output is correct |
35 | Correct | 3 ms | 5252 KB | Output is correct |
36 | Correct | 3 ms | 5212 KB | Output is correct |
37 | Correct | 3 ms | 5212 KB | Output is correct |
38 | Correct | 2 ms | 5212 KB | Output is correct |
39 | Correct | 3 ms | 5472 KB | Output is correct |
40 | Correct | 3 ms | 5216 KB | Output is correct |
41 | Correct | 3 ms | 5208 KB | Output is correct |
42 | Correct | 2 ms | 5212 KB | Output is correct |
43 | Correct | 3 ms | 5212 KB | Output is correct |
44 | Correct | 2 ms | 5172 KB | Output is correct |
45 | Correct | 3 ms | 5212 KB | Output is correct |
46 | Correct | 3 ms | 5212 KB | Output is correct |
47 | Correct | 4 ms | 5284 KB | Output is correct |
48 | Correct | 3 ms | 5212 KB | Output is correct |
49 | Correct | 2 ms | 5212 KB | Output is correct |
50 | Correct | 2 ms | 5212 KB | Output is correct |
51 | Correct | 3 ms | 5212 KB | Output is correct |
52 | Correct | 3 ms | 5208 KB | Output is correct |
53 | Correct | 3 ms | 5212 KB | Output is correct |
54 | Correct | 3 ms | 5212 KB | Output is correct |
55 | Correct | 2 ms | 5212 KB | Output is correct |
56 | Correct | 2 ms | 5212 KB | Output is correct |
57 | Correct | 3 ms | 5212 KB | Output is correct |
58 | Correct | 2 ms | 5244 KB | Output is correct |
59 | Correct | 3 ms | 5212 KB | Output is correct |
60 | Correct | 2 ms | 5212 KB | Output is correct |
61 | Correct | 2 ms | 5196 KB | Output is correct |
62 | Correct | 3 ms | 5212 KB | Output is correct |
63 | Correct | 3 ms | 5212 KB | Output is correct |
64 | Correct | 62 ms | 15316 KB | Output is correct |
65 | Correct | 60 ms | 15312 KB | Output is correct |
66 | Correct | 58 ms | 15296 KB | Output is correct |
67 | Correct | 62 ms | 15308 KB | Output is correct |
68 | Correct | 57 ms | 15308 KB | Output is correct |
69 | Correct | 59 ms | 15308 KB | Output is correct |
70 | Correct | 62 ms | 15324 KB | Output is correct |
71 | Correct | 59 ms | 15328 KB | Output is correct |
72 | Correct | 62 ms | 15340 KB | Output is correct |
73 | Correct | 78 ms | 27852 KB | Output is correct |
74 | Correct | 89 ms | 27836 KB | Output is correct |
75 | Correct | 60 ms | 15052 KB | Output is correct |
76 | Correct | 57 ms | 15052 KB | Output is correct |
77 | Correct | 63 ms | 15232 KB | Output is correct |
78 | Correct | 60 ms | 15052 KB | Output is correct |
79 | Correct | 64 ms | 15060 KB | Output is correct |
80 | Correct | 59 ms | 15052 KB | Output is correct |
81 | Correct | 60 ms | 15556 KB | Output is correct |
82 | Correct | 56 ms | 15244 KB | Output is correct |
83 | Correct | 72 ms | 20688 KB | Output is correct |
84 | Correct | 69 ms | 22492 KB | Output is correct |
85 | Correct | 70 ms | 22164 KB | Output is correct |
86 | Correct | 69 ms | 16616 KB | Output is correct |
87 | Correct | 61 ms | 16072 KB | Output is correct |
88 | Correct | 68 ms | 16392 KB | Output is correct |
89 | Correct | 58 ms | 16348 KB | Output is correct |
90 | Correct | 62 ms | 16172 KB | Output is correct |
91 | Correct | 91 ms | 16504 KB | Output is correct |
92 | Correct | 59 ms | 16828 KB | Output is correct |
93 | Correct | 72 ms | 19104 KB | Output is correct |
94 | Correct | 61 ms | 20936 KB | Output is correct |
95 | Correct | 56 ms | 19588 KB | Output is correct |
96 | Correct | 59 ms | 17824 KB | Output is correct |
97 | Correct | 56 ms | 16312 KB | Output is correct |
98 | Correct | 55 ms | 15872 KB | Output is correct |
99 | Correct | 67 ms | 15564 KB | Output is correct |
100 | Correct | 61 ms | 18788 KB | Output is correct |
101 | Correct | 58 ms | 16708 KB | Output is correct |
102 | Correct | 61 ms | 16028 KB | Output is correct |
103 | Correct | 63 ms | 15832 KB | Output is correct |
104 | Correct | 46 ms | 16032 KB | Output is correct |
105 | Correct | 66 ms | 24528 KB | Output is correct |
106 | Correct | 44 ms | 16068 KB | Output is correct |
107 | Correct | 46 ms | 16068 KB | Output is correct |
108 | Correct | 71 ms | 28572 KB | Output is correct |
109 | Correct | 45 ms | 16072 KB | Output is correct |
110 | Correct | 74 ms | 28880 KB | Output is correct |
111 | Correct | 61 ms | 15040 KB | Output is correct |