# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
788017 | 2023-07-19T16:15:20 Z | YassineBenYounes | Power Plant (JOI20_power) | C++17 | 196 ms | 30300 KB |
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define vi vector<int> #define pii pair<int, int> #define ff first #define ss second #define vii vector<pii> void init(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // ONLINE_JUDGE } const int mx = 3e5+5; const ll mod = 1e9+7; vector<int> graph[mx]; string s; int dp_down[mx]; int ans = 0; void dfs(int node, int p){ int l = 0, sum = 0; for(int adj : graph[node]){ if(adj == p)continue; dfs(adj ,node); sum += dp_down[adj]; l = max(l, dp_down[adj]); } int k = (s[node] == '1'); sum -= k; dp_down[node] = max(dp_down[node], k); dp_down[node] = max(dp_down[node], sum); ans = max(ans, l+k); ans = max(ans, dp_down[node]); } void runcase(){ int n;cin >> n; for(int i = 0; i < n-1;i++){ int a, b;cin >> a >> b; graph[a].pb(b); graph[b].pb(a); } cin >> s; s = "Y" + s; dfs(1, 1); cout << ans << endl; } int main(){ int t; //cin >> t; t = 1; while(t--){ runcase(); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 7356 KB | Output is correct |
2 | Correct | 5 ms | 7252 KB | Output is correct |
3 | Correct | 4 ms | 7356 KB | Output is correct |
4 | Correct | 4 ms | 7252 KB | Output is correct |
5 | Correct | 4 ms | 7252 KB | Output is correct |
6 | Correct | 4 ms | 7260 KB | Output is correct |
7 | Correct | 3 ms | 7348 KB | Output is correct |
8 | Correct | 4 ms | 7252 KB | Output is correct |
9 | Correct | 3 ms | 7352 KB | Output is correct |
10 | Correct | 4 ms | 7252 KB | Output is correct |
11 | Correct | 4 ms | 7252 KB | Output is correct |
12 | Correct | 3 ms | 7356 KB | Output is correct |
13 | Correct | 4 ms | 7252 KB | Output is correct |
14 | Correct | 4 ms | 7252 KB | Output is correct |
15 | Correct | 4 ms | 7352 KB | Output is correct |
16 | Correct | 4 ms | 7252 KB | Output is correct |
17 | Correct | 4 ms | 7252 KB | Output is correct |
18 | Correct | 3 ms | 7252 KB | Output is correct |
19 | Correct | 4 ms | 7252 KB | Output is correct |
20 | Correct | 3 ms | 7252 KB | Output is correct |
21 | Correct | 3 ms | 7252 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 7356 KB | Output is correct |
2 | Correct | 5 ms | 7252 KB | Output is correct |
3 | Correct | 4 ms | 7356 KB | Output is correct |
4 | Correct | 4 ms | 7252 KB | Output is correct |
5 | Correct | 4 ms | 7252 KB | Output is correct |
6 | Correct | 4 ms | 7260 KB | Output is correct |
7 | Correct | 3 ms | 7348 KB | Output is correct |
8 | Correct | 4 ms | 7252 KB | Output is correct |
9 | Correct | 3 ms | 7352 KB | Output is correct |
10 | Correct | 4 ms | 7252 KB | Output is correct |
11 | Correct | 4 ms | 7252 KB | Output is correct |
12 | Correct | 3 ms | 7356 KB | Output is correct |
13 | Correct | 4 ms | 7252 KB | Output is correct |
14 | Correct | 4 ms | 7252 KB | Output is correct |
15 | Correct | 4 ms | 7352 KB | Output is correct |
16 | Correct | 4 ms | 7252 KB | Output is correct |
17 | Correct | 4 ms | 7252 KB | Output is correct |
18 | Correct | 3 ms | 7252 KB | Output is correct |
19 | Correct | 4 ms | 7252 KB | Output is correct |
20 | Correct | 3 ms | 7252 KB | Output is correct |
21 | Correct | 3 ms | 7252 KB | Output is correct |
22 | Correct | 5 ms | 7380 KB | Output is correct |
23 | Correct | 7 ms | 7380 KB | Output is correct |
24 | Correct | 5 ms | 7380 KB | Output is correct |
25 | Correct | 5 ms | 7364 KB | Output is correct |
26 | Correct | 5 ms | 7380 KB | Output is correct |
27 | Correct | 5 ms | 7380 KB | Output is correct |
28 | Correct | 5 ms | 7380 KB | Output is correct |
29 | Correct | 5 ms | 7496 KB | Output is correct |
30 | Correct | 5 ms | 7508 KB | Output is correct |
31 | Correct | 4 ms | 7340 KB | Output is correct |
32 | Correct | 4 ms | 7380 KB | Output is correct |
33 | Correct | 4 ms | 7420 KB | Output is correct |
34 | Correct | 4 ms | 7380 KB | Output is correct |
35 | Correct | 4 ms | 7380 KB | Output is correct |
36 | Correct | 4 ms | 7380 KB | Output is correct |
37 | Correct | 5 ms | 7380 KB | Output is correct |
38 | Correct | 5 ms | 7380 KB | Output is correct |
39 | Correct | 4 ms | 7380 KB | Output is correct |
40 | Correct | 5 ms | 7380 KB | Output is correct |
41 | Correct | 4 ms | 7488 KB | Output is correct |
42 | Correct | 5 ms | 7380 KB | Output is correct |
43 | Correct | 4 ms | 7380 KB | Output is correct |
44 | Correct | 4 ms | 7364 KB | Output is correct |
45 | Correct | 4 ms | 7380 KB | Output is correct |
46 | Correct | 5 ms | 7380 KB | Output is correct |
47 | Correct | 4 ms | 7380 KB | Output is correct |
48 | Correct | 4 ms | 7508 KB | Output is correct |
49 | Correct | 4 ms | 7492 KB | Output is correct |
50 | Correct | 4 ms | 7488 KB | Output is correct |
51 | Correct | 5 ms | 7380 KB | Output is correct |
52 | Correct | 5 ms | 7364 KB | Output is correct |
53 | Correct | 6 ms | 7380 KB | Output is correct |
54 | Correct | 5 ms | 7380 KB | Output is correct |
55 | Correct | 5 ms | 7380 KB | Output is correct |
56 | Correct | 5 ms | 7380 KB | Output is correct |
57 | Correct | 4 ms | 7508 KB | Output is correct |
58 | Correct | 5 ms | 7380 KB | Output is correct |
59 | Correct | 4 ms | 7380 KB | Output is correct |
60 | Correct | 10 ms | 7508 KB | Output is correct |
61 | Correct | 5 ms | 7380 KB | Output is correct |
62 | Correct | 4 ms | 7508 KB | Output is correct |
63 | Correct | 4 ms | 7364 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 7356 KB | Output is correct |
2 | Correct | 5 ms | 7252 KB | Output is correct |
3 | Correct | 4 ms | 7356 KB | Output is correct |
4 | Correct | 4 ms | 7252 KB | Output is correct |
5 | Correct | 4 ms | 7252 KB | Output is correct |
6 | Correct | 4 ms | 7260 KB | Output is correct |
7 | Correct | 3 ms | 7348 KB | Output is correct |
8 | Correct | 4 ms | 7252 KB | Output is correct |
9 | Correct | 3 ms | 7352 KB | Output is correct |
10 | Correct | 4 ms | 7252 KB | Output is correct |
11 | Correct | 4 ms | 7252 KB | Output is correct |
12 | Correct | 3 ms | 7356 KB | Output is correct |
13 | Correct | 4 ms | 7252 KB | Output is correct |
14 | Correct | 4 ms | 7252 KB | Output is correct |
15 | Correct | 4 ms | 7352 KB | Output is correct |
16 | Correct | 4 ms | 7252 KB | Output is correct |
17 | Correct | 4 ms | 7252 KB | Output is correct |
18 | Correct | 3 ms | 7252 KB | Output is correct |
19 | Correct | 4 ms | 7252 KB | Output is correct |
20 | Correct | 3 ms | 7252 KB | Output is correct |
21 | Correct | 3 ms | 7252 KB | Output is correct |
22 | Correct | 5 ms | 7380 KB | Output is correct |
23 | Correct | 7 ms | 7380 KB | Output is correct |
24 | Correct | 5 ms | 7380 KB | Output is correct |
25 | Correct | 5 ms | 7364 KB | Output is correct |
26 | Correct | 5 ms | 7380 KB | Output is correct |
27 | Correct | 5 ms | 7380 KB | Output is correct |
28 | Correct | 5 ms | 7380 KB | Output is correct |
29 | Correct | 5 ms | 7496 KB | Output is correct |
30 | Correct | 5 ms | 7508 KB | Output is correct |
31 | Correct | 4 ms | 7340 KB | Output is correct |
32 | Correct | 4 ms | 7380 KB | Output is correct |
33 | Correct | 4 ms | 7420 KB | Output is correct |
34 | Correct | 4 ms | 7380 KB | Output is correct |
35 | Correct | 4 ms | 7380 KB | Output is correct |
36 | Correct | 4 ms | 7380 KB | Output is correct |
37 | Correct | 5 ms | 7380 KB | Output is correct |
38 | Correct | 5 ms | 7380 KB | Output is correct |
39 | Correct | 4 ms | 7380 KB | Output is correct |
40 | Correct | 5 ms | 7380 KB | Output is correct |
41 | Correct | 4 ms | 7488 KB | Output is correct |
42 | Correct | 5 ms | 7380 KB | Output is correct |
43 | Correct | 4 ms | 7380 KB | Output is correct |
44 | Correct | 4 ms | 7364 KB | Output is correct |
45 | Correct | 4 ms | 7380 KB | Output is correct |
46 | Correct | 5 ms | 7380 KB | Output is correct |
47 | Correct | 4 ms | 7380 KB | Output is correct |
48 | Correct | 4 ms | 7508 KB | Output is correct |
49 | Correct | 4 ms | 7492 KB | Output is correct |
50 | Correct | 4 ms | 7488 KB | Output is correct |
51 | Correct | 5 ms | 7380 KB | Output is correct |
52 | Correct | 5 ms | 7364 KB | Output is correct |
53 | Correct | 6 ms | 7380 KB | Output is correct |
54 | Correct | 5 ms | 7380 KB | Output is correct |
55 | Correct | 5 ms | 7380 KB | Output is correct |
56 | Correct | 5 ms | 7380 KB | Output is correct |
57 | Correct | 4 ms | 7508 KB | Output is correct |
58 | Correct | 5 ms | 7380 KB | Output is correct |
59 | Correct | 4 ms | 7380 KB | Output is correct |
60 | Correct | 10 ms | 7508 KB | Output is correct |
61 | Correct | 5 ms | 7380 KB | Output is correct |
62 | Correct | 4 ms | 7508 KB | Output is correct |
63 | Correct | 4 ms | 7364 KB | Output is correct |
64 | Correct | 142 ms | 16572 KB | Output is correct |
65 | Correct | 196 ms | 16516 KB | Output is correct |
66 | Correct | 161 ms | 16612 KB | Output is correct |
67 | Correct | 154 ms | 16548 KB | Output is correct |
68 | Correct | 163 ms | 16588 KB | Output is correct |
69 | Correct | 132 ms | 16520 KB | Output is correct |
70 | Correct | 171 ms | 16500 KB | Output is correct |
71 | Correct | 134 ms | 16536 KB | Output is correct |
72 | Correct | 141 ms | 16564 KB | Output is correct |
73 | Correct | 160 ms | 29160 KB | Output is correct |
74 | Correct | 175 ms | 29108 KB | Output is correct |
75 | Correct | 131 ms | 16472 KB | Output is correct |
76 | Correct | 164 ms | 16504 KB | Output is correct |
77 | Correct | 170 ms | 16500 KB | Output is correct |
78 | Correct | 144 ms | 16476 KB | Output is correct |
79 | Correct | 134 ms | 16500 KB | Output is correct |
80 | Correct | 157 ms | 16448 KB | Output is correct |
81 | Correct | 124 ms | 16896 KB | Output is correct |
82 | Correct | 137 ms | 16556 KB | Output is correct |
83 | Correct | 160 ms | 21724 KB | Output is correct |
84 | Correct | 146 ms | 23732 KB | Output is correct |
85 | Correct | 166 ms | 23580 KB | Output is correct |
86 | Correct | 147 ms | 17956 KB | Output is correct |
87 | Correct | 159 ms | 17376 KB | Output is correct |
88 | Correct | 129 ms | 17764 KB | Output is correct |
89 | Correct | 148 ms | 17904 KB | Output is correct |
90 | Correct | 134 ms | 17556 KB | Output is correct |
91 | Correct | 139 ms | 17816 KB | Output is correct |
92 | Correct | 135 ms | 18160 KB | Output is correct |
93 | Correct | 145 ms | 20596 KB | Output is correct |
94 | Correct | 145 ms | 22340 KB | Output is correct |
95 | Correct | 150 ms | 20896 KB | Output is correct |
96 | Correct | 132 ms | 19100 KB | Output is correct |
97 | Correct | 133 ms | 17588 KB | Output is correct |
98 | Correct | 131 ms | 17112 KB | Output is correct |
99 | Correct | 148 ms | 16892 KB | Output is correct |
100 | Correct | 141 ms | 20100 KB | Output is correct |
101 | Correct | 135 ms | 18092 KB | Output is correct |
102 | Correct | 152 ms | 17324 KB | Output is correct |
103 | Correct | 130 ms | 17108 KB | Output is correct |
104 | Correct | 126 ms | 17536 KB | Output is correct |
105 | Correct | 166 ms | 25964 KB | Output is correct |
106 | Correct | 109 ms | 17284 KB | Output is correct |
107 | Correct | 107 ms | 17380 KB | Output is correct |
108 | Correct | 160 ms | 29952 KB | Output is correct |
109 | Correct | 115 ms | 17340 KB | Output is correct |
110 | Correct | 149 ms | 30300 KB | Output is correct |
111 | Correct | 140 ms | 16432 KB | Output is correct |