Submission #1037061

# Submission time Handle Problem Language Result Execution time Memory
1037061 2024-07-28T01:25:29 Z model_code The Ties That Guide Us (CEOI23_incursion) C++17
100 / 100
406 ms 15528 KB
#include "incursion.h"
#include <bits/stdc++.h>
using namespace std;

int n;
vector<vector<int>> adj;
vector<int> parent;
vector<int> depth;
vector<int> subtree_size;

void dfs(int from, int d = 0) {
    depth[from] = d;
    for (int j: adj[from]) {
        if (j == parent[from]) continue;
        parent[j] = from;
        dfs(j, d + 1);
        subtree_size[from] += subtree_size[j];
    }
}

int find_center(int treasure_pos) {
    parent.assign(n, -1);
    depth.assign(n, -1);
    subtree_size.assign(n, 0);

    dfs(treasure_pos);
    int end1 = 0;
    for (int i = 1; i < n; ++i)
        if (depth[i] > depth[end1]) end1 = i;

    parent[end1] = -1;
    dfs(end1);
    int end2 = 0;
    for (int i = 1; i < n; ++i)
        if (depth[i] > depth[end2]) end2 = i;

    int center = end2;
    while (depth[center] * 2 > depth[end2] + 1) center = parent[center];

    subtree_size.assign(n, 1);
    parent[center] = -1;
    dfs(center);
    return center;
}

void to_adj_list(const vector<pair<int, int>>& edges) {
    n = edges.size() + 1;
    adj.assign(n, {});
    for (auto [a, b]: edges) {
        --a;
        --b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
}

vector<int> mark(vector<pair<int, int>> F, int safe) {
    --safe;
    to_adj_list(F);
    find_center(safe);
    vector<int> ties(n, 0);
    do {
        ties[safe] = 1;
        safe = parent[safe];
    } while (safe != -1);
    return ties;
}

void locate(vector<pair<int, int>> F, int curr, int t) {
    --curr;
    to_adj_list(F);
    find_center(0);
    while (t == 0 && parent[curr] != -1) {
        curr = parent[curr];
        assert(curr != -1);
        t = visit(curr + 1);
    }
    for (;;) {
        sort(adj[curr].begin(), adj[curr].end(), [&](int a, int b){ return subtree_size[a] > subtree_size[b]; });
        bool found = false;
        for (int j: adj[curr]) {
            if (j == parent[curr]) continue;
            t = visit(j + 1);
            if (t) {
                found = true;
                curr = j;
                break;
            }
            t = visit(curr + 1);
        }
        if (!found) return;
    }
}

Compilation message

interface.cpp: In function 'int main()':
interface.cpp:44:55: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   44 |     if(fread(T.data(), sizeof(int), 2 * N - 2, stdin) != 2 * N - 2) exit(0);
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
interface.cpp:50:33: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   50 |         int l = (numbers.size() == N ? N : 0);
      |                  ~~~~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 752 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 301 ms 15360 KB Correct
2 Correct 295 ms 15404 KB Correct
3 Correct 164 ms 15344 KB Correct
4 Correct 142 ms 15336 KB Correct
5 Correct 260 ms 15336 KB Correct
6 Correct 123 ms 15176 KB Correct
7 Correct 114 ms 15072 KB Correct
8 Correct 302 ms 15404 KB Correct
9 Correct 294 ms 15336 KB Correct
10 Correct 237 ms 15336 KB Correct
11 Correct 156 ms 15400 KB Correct
12 Correct 377 ms 15328 KB Correct
13 Correct 112 ms 15116 KB Correct
14 Correct 118 ms 15176 KB Correct
15 Correct 289 ms 15400 KB Correct
16 Correct 293 ms 15332 KB Correct
17 Correct 203 ms 15116 KB Correct
18 Correct 122 ms 15180 KB Correct
19 Correct 219 ms 15336 KB Correct
20 Correct 138 ms 15312 KB Correct
21 Correct 132 ms 15344 KB Correct
22 Correct 299 ms 15340 KB Correct
23 Correct 298 ms 15292 KB Correct
24 Correct 138 ms 15432 KB Correct
25 Correct 140 ms 15444 KB Correct
26 Correct 125 ms 15400 KB Correct
27 Correct 132 ms 15124 KB Correct
28 Correct 129 ms 15112 KB Correct
29 Correct 334 ms 15332 KB Correct
30 Correct 313 ms 15340 KB Correct
31 Correct 130 ms 15368 KB Correct
32 Correct 355 ms 15408 KB Correct
33 Correct 325 ms 15336 KB Correct
34 Correct 115 ms 15116 KB Correct
35 Correct 123 ms 15112 KB Correct
36 Correct 301 ms 15288 KB Correct
37 Correct 303 ms 15356 KB Correct
38 Correct 369 ms 15396 KB Correct
39 Correct 205 ms 15404 KB Correct
40 Correct 270 ms 14996 KB Correct
41 Correct 132 ms 15112 KB Correct
42 Correct 129 ms 15116 KB Correct
43 Correct 319 ms 15336 KB Correct
44 Correct 306 ms 15336 KB Correct
45 Correct 132 ms 15124 KB Correct
46 Correct 141 ms 15256 KB Correct
47 Correct 150 ms 15332 KB Correct
48 Correct 139 ms 15116 KB Correct
49 Correct 121 ms 15176 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 108 ms 8200 KB Correct
2 Correct 105 ms 8472 KB Correct
3 Correct 106 ms 8200 KB Correct
4 Correct 120 ms 11516 KB Correct
5 Correct 194 ms 11880 KB Correct
6 Correct 221 ms 11532 KB Correct
7 Correct 103 ms 8000 KB Correct
8 Correct 109 ms 8220 KB Correct
9 Correct 109 ms 8000 KB Correct
10 Correct 109 ms 8008 KB Correct
11 Correct 111 ms 7936 KB Correct
12 Correct 110 ms 7976 KB Correct
13 Correct 111 ms 8004 KB Correct
14 Correct 80 ms 6392 KB Correct
15 Correct 72 ms 6212 KB Correct
16 Correct 103 ms 7928 KB Correct
17 Correct 108 ms 8008 KB Correct
18 Correct 109 ms 8008 KB Correct
19 Correct 111 ms 8128 KB Correct
20 Correct 71 ms 6124 KB Correct
21 Correct 73 ms 6220 KB Correct
22 Correct 74 ms 6480 KB Correct
23 Correct 88 ms 6124 KB Correct
24 Correct 79 ms 6056 KB Correct
25 Correct 72 ms 6284 KB Correct
26 Correct 114 ms 8268 KB Correct
27 Correct 112 ms 8264 KB Correct
28 Correct 109 ms 8168 KB Correct
29 Correct 100 ms 8272 KB Correct
30 Correct 120 ms 8204 KB Correct
31 Correct 127 ms 8264 KB Correct
32 Correct 110 ms 8440 KB Correct
33 Correct 121 ms 8268 KB Correct
34 Correct 113 ms 8204 KB Correct
35 Correct 110 ms 8184 KB Correct
36 Correct 118 ms 8488 KB Correct
37 Correct 107 ms 8008 KB Correct
38 Correct 98 ms 8008 KB Correct
39 Correct 115 ms 8200 KB Correct
40 Correct 109 ms 8192 KB Correct
41 Correct 110 ms 8004 KB Correct
42 Correct 100 ms 8520 KB Correct
43 Correct 114 ms 8204 KB Correct
44 Correct 112 ms 8268 KB Correct
45 Correct 122 ms 8452 KB Correct
46 Correct 121 ms 8264 KB Correct
47 Correct 112 ms 8268 KB Correct
48 Correct 118 ms 8368 KB Correct
49 Correct 126 ms 8076 KB Correct
50 Correct 107 ms 8268 KB Correct
51 Correct 100 ms 8456 KB Correct
52 Correct 108 ms 8240 KB Correct
53 Correct 115 ms 8192 KB Correct
54 Correct 105 ms 8196 KB Correct
55 Correct 101 ms 8192 KB Correct
56 Correct 106 ms 8460 KB Correct
57 Correct 104 ms 8588 KB Correct
58 Correct 114 ms 8460 KB Correct
59 Correct 113 ms 8540 KB Correct
60 Correct 112 ms 8360 KB Correct
61 Correct 122 ms 8496 KB Correct
62 Correct 107 ms 8588 KB Correct
63 Correct 107 ms 8452 KB Correct
64 Correct 102 ms 8440 KB Correct
65 Correct 132 ms 8444 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 752 KB Correct
2 Correct 301 ms 15360 KB Correct
3 Correct 295 ms 15404 KB Correct
4 Correct 164 ms 15344 KB Correct
5 Correct 142 ms 15336 KB Correct
6 Correct 260 ms 15336 KB Correct
7 Correct 123 ms 15176 KB Correct
8 Correct 114 ms 15072 KB Correct
9 Correct 302 ms 15404 KB Correct
10 Correct 294 ms 15336 KB Correct
11 Correct 237 ms 15336 KB Correct
12 Correct 156 ms 15400 KB Correct
13 Correct 377 ms 15328 KB Correct
14 Correct 112 ms 15116 KB Correct
15 Correct 118 ms 15176 KB Correct
16 Correct 289 ms 15400 KB Correct
17 Correct 293 ms 15332 KB Correct
18 Correct 203 ms 15116 KB Correct
19 Correct 122 ms 15180 KB Correct
20 Correct 219 ms 15336 KB Correct
21 Correct 138 ms 15312 KB Correct
22 Correct 132 ms 15344 KB Correct
23 Correct 299 ms 15340 KB Correct
24 Correct 298 ms 15292 KB Correct
25 Correct 138 ms 15432 KB Correct
26 Correct 140 ms 15444 KB Correct
27 Correct 125 ms 15400 KB Correct
28 Correct 132 ms 15124 KB Correct
29 Correct 129 ms 15112 KB Correct
30 Correct 334 ms 15332 KB Correct
31 Correct 313 ms 15340 KB Correct
32 Correct 130 ms 15368 KB Correct
33 Correct 355 ms 15408 KB Correct
34 Correct 325 ms 15336 KB Correct
35 Correct 115 ms 15116 KB Correct
36 Correct 123 ms 15112 KB Correct
37 Correct 301 ms 15288 KB Correct
38 Correct 303 ms 15356 KB Correct
39 Correct 369 ms 15396 KB Correct
40 Correct 205 ms 15404 KB Correct
41 Correct 270 ms 14996 KB Correct
42 Correct 132 ms 15112 KB Correct
43 Correct 129 ms 15116 KB Correct
44 Correct 319 ms 15336 KB Correct
45 Correct 306 ms 15336 KB Correct
46 Correct 132 ms 15124 KB Correct
47 Correct 141 ms 15256 KB Correct
48 Correct 150 ms 15332 KB Correct
49 Correct 139 ms 15116 KB Correct
50 Correct 121 ms 15176 KB Correct
51 Correct 108 ms 8200 KB Correct
52 Correct 105 ms 8472 KB Correct
53 Correct 106 ms 8200 KB Correct
54 Correct 120 ms 11516 KB Correct
55 Correct 194 ms 11880 KB Correct
56 Correct 221 ms 11532 KB Correct
57 Correct 103 ms 8000 KB Correct
58 Correct 109 ms 8220 KB Correct
59 Correct 109 ms 8000 KB Correct
60 Correct 109 ms 8008 KB Correct
61 Correct 111 ms 7936 KB Correct
62 Correct 110 ms 7976 KB Correct
63 Correct 111 ms 8004 KB Correct
64 Correct 80 ms 6392 KB Correct
65 Correct 72 ms 6212 KB Correct
66 Correct 103 ms 7928 KB Correct
67 Correct 108 ms 8008 KB Correct
68 Correct 109 ms 8008 KB Correct
69 Correct 111 ms 8128 KB Correct
70 Correct 71 ms 6124 KB Correct
71 Correct 73 ms 6220 KB Correct
72 Correct 74 ms 6480 KB Correct
73 Correct 88 ms 6124 KB Correct
74 Correct 79 ms 6056 KB Correct
75 Correct 72 ms 6284 KB Correct
76 Correct 114 ms 8268 KB Correct
77 Correct 112 ms 8264 KB Correct
78 Correct 109 ms 8168 KB Correct
79 Correct 100 ms 8272 KB Correct
80 Correct 120 ms 8204 KB Correct
81 Correct 127 ms 8264 KB Correct
82 Correct 110 ms 8440 KB Correct
83 Correct 121 ms 8268 KB Correct
84 Correct 113 ms 8204 KB Correct
85 Correct 110 ms 8184 KB Correct
86 Correct 118 ms 8488 KB Correct
87 Correct 107 ms 8008 KB Correct
88 Correct 98 ms 8008 KB Correct
89 Correct 115 ms 8200 KB Correct
90 Correct 109 ms 8192 KB Correct
91 Correct 110 ms 8004 KB Correct
92 Correct 100 ms 8520 KB Correct
93 Correct 114 ms 8204 KB Correct
94 Correct 112 ms 8268 KB Correct
95 Correct 122 ms 8452 KB Correct
96 Correct 121 ms 8264 KB Correct
97 Correct 112 ms 8268 KB Correct
98 Correct 118 ms 8368 KB Correct
99 Correct 126 ms 8076 KB Correct
100 Correct 107 ms 8268 KB Correct
101 Correct 100 ms 8456 KB Correct
102 Correct 108 ms 8240 KB Correct
103 Correct 115 ms 8192 KB Correct
104 Correct 105 ms 8196 KB Correct
105 Correct 101 ms 8192 KB Correct
106 Correct 106 ms 8460 KB Correct
107 Correct 104 ms 8588 KB Correct
108 Correct 114 ms 8460 KB Correct
109 Correct 113 ms 8540 KB Correct
110 Correct 112 ms 8360 KB Correct
111 Correct 122 ms 8496 KB Correct
112 Correct 107 ms 8588 KB Correct
113 Correct 107 ms 8452 KB Correct
114 Correct 102 ms 8440 KB Correct
115 Correct 132 ms 8444 KB Correct
116 Correct 130 ms 8448 KB Correct
117 Correct 129 ms 8712 KB Correct
118 Correct 116 ms 8548 KB Correct
119 Correct 132 ms 8524 KB Correct
120 Correct 129 ms 8452 KB Correct
121 Correct 125 ms 8536 KB Correct
122 Correct 132 ms 8288 KB Correct
123 Correct 153 ms 11780 KB Correct
124 Correct 206 ms 11852 KB Correct
125 Correct 244 ms 11716 KB Correct
126 Correct 123 ms 8148 KB Correct
127 Correct 128 ms 8240 KB Correct
128 Correct 94 ms 8236 KB Correct
129 Correct 105 ms 8120 KB Correct
130 Correct 115 ms 7908 KB Correct
131 Correct 127 ms 7972 KB Correct
132 Correct 121 ms 8008 KB Correct
133 Correct 74 ms 6268 KB Correct
134 Correct 79 ms 6224 KB Correct
135 Correct 110 ms 7936 KB Correct
136 Correct 114 ms 7912 KB Correct
137 Correct 112 ms 7932 KB Correct
138 Correct 119 ms 8012 KB Correct
139 Correct 74 ms 6124 KB Correct
140 Correct 74 ms 6224 KB Correct
141 Correct 70 ms 6224 KB Correct
142 Correct 75 ms 6324 KB Correct
143 Correct 77 ms 6220 KB Correct
144 Correct 88 ms 6124 KB Correct
145 Correct 119 ms 8268 KB Correct
146 Correct 121 ms 8192 KB Correct
147 Correct 120 ms 8228 KB Correct
148 Correct 110 ms 8260 KB Correct
149 Correct 112 ms 8464 KB Correct
150 Correct 134 ms 8188 KB Correct
151 Correct 109 ms 8008 KB Correct
152 Correct 105 ms 8200 KB Correct
153 Correct 103 ms 8204 KB Correct
154 Correct 97 ms 8012 KB Correct
155 Correct 118 ms 8008 KB Correct
156 Correct 113 ms 8216 KB Correct
157 Correct 112 ms 8192 KB Correct
158 Correct 103 ms 8208 KB Correct
159 Correct 104 ms 8276 KB Correct
160 Correct 102 ms 7992 KB Correct
161 Correct 103 ms 8264 KB Correct
162 Correct 112 ms 8204 KB Correct
163 Correct 110 ms 8272 KB Correct
164 Correct 99 ms 8196 KB Correct
165 Correct 115 ms 8320 KB Correct
166 Correct 102 ms 8264 KB Correct
167 Correct 117 ms 8208 KB Correct
168 Correct 111 ms 8200 KB Correct
169 Correct 125 ms 8272 KB Correct
170 Correct 129 ms 8188 KB Correct
171 Correct 123 ms 8264 KB Correct
172 Correct 106 ms 8260 KB Correct
173 Correct 103 ms 8268 KB Correct
174 Correct 101 ms 8196 KB Correct
175 Correct 111 ms 8596 KB Correct
176 Correct 95 ms 8592 KB Correct
177 Correct 126 ms 8424 KB Correct
178 Correct 96 ms 8460 KB Correct
179 Correct 105 ms 8528 KB Correct
180 Correct 111 ms 8260 KB Correct
181 Correct 114 ms 8592 KB Correct
182 Correct 101 ms 8536 KB Correct
183 Correct 99 ms 8516 KB Correct
184 Correct 124 ms 8332 KB Correct
185 Correct 309 ms 15400 KB Correct
186 Correct 295 ms 15336 KB Correct
187 Correct 152 ms 15440 KB Correct
188 Correct 148 ms 15332 KB Correct
189 Correct 275 ms 15328 KB Correct
190 Correct 111 ms 15120 KB Correct
191 Correct 113 ms 15136 KB Correct
192 Correct 314 ms 15484 KB Correct
193 Correct 316 ms 15364 KB Correct
194 Correct 232 ms 15408 KB Correct
195 Correct 163 ms 15528 KB Correct
196 Correct 406 ms 15336 KB Correct
197 Correct 104 ms 15176 KB Correct
198 Correct 124 ms 15160 KB Correct
199 Correct 305 ms 15336 KB Correct
200 Correct 309 ms 15372 KB Correct
201 Correct 190 ms 15252 KB Correct
202 Correct 123 ms 15180 KB Correct
203 Correct 226 ms 15400 KB Correct
204 Correct 137 ms 15116 KB Correct
205 Correct 134 ms 15172 KB Correct
206 Correct 296 ms 15332 KB Correct
207 Correct 296 ms 15400 KB Correct
208 Correct 136 ms 15432 KB Correct
209 Correct 126 ms 15112 KB Correct
210 Correct 124 ms 15184 KB Correct
211 Correct 121 ms 15124 KB Correct
212 Correct 126 ms 15116 KB Correct
213 Correct 306 ms 15332 KB Correct
214 Correct 330 ms 15332 KB Correct
215 Correct 137 ms 15408 KB Correct
216 Correct 330 ms 15336 KB Correct
217 Correct 335 ms 15348 KB Correct
218 Correct 110 ms 15176 KB Correct
219 Correct 119 ms 15268 KB Correct
220 Correct 296 ms 15332 KB Correct
221 Correct 286 ms 15372 KB Correct
222 Correct 356 ms 15340 KB Correct
223 Correct 212 ms 15276 KB Correct
224 Correct 274 ms 15444 KB Correct
225 Correct 117 ms 15248 KB Correct
226 Correct 124 ms 15184 KB Correct
227 Correct 317 ms 15400 KB Correct
228 Correct 322 ms 15336 KB Correct
229 Correct 130 ms 15116 KB Correct
230 Correct 119 ms 15140 KB Correct
231 Correct 144 ms 15136 KB Correct
232 Correct 123 ms 15120 KB Correct
233 Correct 115 ms 15384 KB Correct
234 Correct 120 ms 11856 KB Correct
235 Correct 145 ms 11528 KB Correct
236 Correct 73 ms 6268 KB Correct
237 Correct 79 ms 6224 KB Correct
238 Correct 82 ms 6128 KB Correct
239 Correct 51 ms 4792 KB Correct
240 Correct 107 ms 8200 KB Correct
241 Correct 109 ms 8212 KB Correct
242 Correct 108 ms 8008 KB Correct
243 Correct 107 ms 8240 KB Correct
244 Correct 118 ms 8200 KB Correct
245 Correct 106 ms 8288 KB Correct
246 Correct 103 ms 8264 KB Correct
247 Correct 115 ms 8080 KB Correct
248 Correct 111 ms 8208 KB Correct
249 Correct 121 ms 8240 KB Correct
250 Correct 113 ms 8196 KB Correct
251 Correct 120 ms 8192 KB Correct
252 Correct 118 ms 8008 KB Correct
253 Correct 99 ms 8268 KB Correct
254 Correct 117 ms 8208 KB Correct
255 Correct 109 ms 8244 KB Correct
256 Correct 115 ms 8012 KB Correct
257 Correct 97 ms 8044 KB Correct
258 Correct 121 ms 8200 KB Correct
259 Correct 113 ms 8236 KB Correct
260 Correct 103 ms 8056 KB Correct
261 Correct 101 ms 8264 KB Correct
262 Correct 103 ms 8288 KB Correct
263 Correct 117 ms 8264 KB Correct
264 Correct 118 ms 8168 KB Correct
265 Correct 70 ms 6216 KB Correct
266 Correct 87 ms 6468 KB Correct
267 Correct 89 ms 6392 KB Correct
268 Correct 79 ms 6124 KB Correct
269 Correct 81 ms 6228 KB Correct
270 Correct 84 ms 6228 KB Correct
271 Correct 65 ms 6028 KB Correct
272 Correct 82 ms 6124 KB Correct
273 Correct 74 ms 6220 KB Correct
274 Correct 79 ms 6368 KB Correct
275 Correct 73 ms 6124 KB Correct
276 Correct 82 ms 6128 KB Correct
277 Correct 79 ms 6076 KB Correct
278 Correct 88 ms 6220 KB Correct
279 Correct 80 ms 6212 KB Correct
280 Correct 107 ms 8512 KB Correct
281 Correct 119 ms 8532 KB Correct
282 Correct 118 ms 8456 KB Correct
283 Correct 102 ms 8452 KB Correct
284 Correct 103 ms 8520 KB Correct
285 Correct 114 ms 8452 KB Correct
286 Correct 119 ms 8528 KB Correct
287 Correct 119 ms 8640 KB Correct
288 Correct 111 ms 8540 KB Correct
289 Correct 95 ms 8440 KB Correct