Submission #1072282

# Submission time Handle Problem Language Result Execution time Memory
1072282 2024-08-23T16:20:11 Z Wael The Ties That Guide Us (CEOI23_incursion) C++17
100 / 100
289 ms 16844 KB
#include <bits/stdc++.h>
#include "incursion.h"
//#include "sample_grader.cpp"
using namespace std;

vector<int> mark(vector<pair<int, int>> F, int safe) {
    --safe;
    int n = F.size() + 1;
    vector<vector<int>> adj(n);
    for (auto [u, v] : F) {
        --u, --v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    vector<int> sz(n, 1), t(n);
    function<void(int, int)> dfs = [&](int u, int p) {
        for (auto v : adj[u]) {
            if (v == p) {
                continue;
            }
            dfs(v, u);
            sz[u] += sz[v];
        }
        if (u != safe && n - sz[u] >= sz[u]) {
            t[u] = 1;
        }
    };
    dfs(safe, -1);

    return t;
}

void locate(vector<pair<int, int>> F, int curr, int t) {
    --curr;
    int n = F.size() + 1;
    vector<vector<int>> adj(n);
    for (auto [u, v] : F) {
        --u, --v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    vector<int> sz(n, 1), par(n, -1);
    function<void(int, int)> calc = [&](int u, int p) {
        for (auto v : adj[u]) {
            if (v == p) {
                continue;
            }
            calc(v, u);
            sz[u] += sz[v];
        }

        if (n - sz[u] == sz[u]) {
            par[u] = p;
            par[p] = u;
        } else if (n - sz[u] > sz[u]) {
            par[u] = p;
        } else if (p != -1) {
            par[p] = u;
        }
    };
    calc(0, -1);

    fill(sz.begin(), sz.end(), 1);
    for (int i = 0; i < n; ++i) {
        if (par[i] == -1) {
            calc(i, -1);
        }
        if (par[par[i]] == i) {
            calc(i, -1);
            sz[par[i]] = n;
            break;
        }
    }

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < adj[i].size(); ++j) {
            int v = adj[i][j];
            if (v == par[i]) {
                swap(adj[i][j], adj[i].back());
                adj[i].pop_back();
                break;
            }
        }
        sort(adj[i].begin(), adj[i].end(), [&](int u, int v) {
            return sz[u] > sz[v];
        });
    }

    vector<int> cnt(n);
    function<void(int)> dfs = [&](int u) {
        ++cnt[u];
        if (t == 1) {
            t = visit(par[u] + 1);
            dfs(par[u]);
        } else {
            if (int(adj[u].size()) < cnt[u]) {
                return;
            }
            t = visit(adj[u][cnt[u] - 1] + 1);
            dfs(adj[u][cnt[u] - 1]);
        }
    };
    dfs(curr);

    return;
}

Compilation message

incursion.cpp: In function 'void locate(std::vector<std::pair<int, int> >, int, int)':
incursion.cpp:78:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |         for (int j = 0; j < adj[i].size(); ++j) {
      |                         ~~^~~~~~~~~~~~~~~
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 0 ms 1016 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 195 ms 15200 KB Correct
2 Correct 221 ms 16156 KB Correct
3 Correct 100 ms 16248 KB Correct
4 Correct 113 ms 15264 KB Correct
5 Correct 216 ms 16212 KB Correct
6 Correct 78 ms 14412 KB Correct
7 Correct 81 ms 13400 KB Correct
8 Correct 205 ms 15380 KB Correct
9 Correct 218 ms 16728 KB Correct
10 Correct 164 ms 14968 KB Correct
11 Correct 106 ms 16024 KB Correct
12 Correct 279 ms 15088 KB Correct
13 Correct 80 ms 12896 KB Correct
14 Correct 82 ms 12700 KB Correct
15 Correct 198 ms 15964 KB Correct
16 Correct 241 ms 16804 KB Correct
17 Correct 135 ms 13660 KB Correct
18 Correct 98 ms 13932 KB Correct
19 Correct 181 ms 13172 KB Correct
20 Correct 81 ms 14172 KB Correct
21 Correct 90 ms 13920 KB Correct
22 Correct 210 ms 15748 KB Correct
23 Correct 231 ms 16468 KB Correct
24 Correct 95 ms 14184 KB Correct
25 Correct 101 ms 15204 KB Correct
26 Correct 90 ms 13940 KB Correct
27 Correct 77 ms 13392 KB Correct
28 Correct 82 ms 12364 KB Correct
29 Correct 214 ms 16844 KB Correct
30 Correct 225 ms 15184 KB Correct
31 Correct 91 ms 15192 KB Correct
32 Correct 265 ms 14596 KB Correct
33 Correct 275 ms 15036 KB Correct
34 Correct 90 ms 12656 KB Correct
35 Correct 84 ms 13224 KB Correct
36 Correct 228 ms 15908 KB Correct
37 Correct 219 ms 16708 KB Correct
38 Correct 270 ms 15560 KB Correct
39 Correct 149 ms 15968 KB Correct
40 Correct 213 ms 15052 KB Correct
41 Correct 83 ms 13216 KB Correct
42 Correct 81 ms 14168 KB Correct
43 Correct 216 ms 15896 KB Correct
44 Correct 222 ms 14904 KB Correct
45 Correct 88 ms 14504 KB Correct
46 Correct 93 ms 15144 KB Correct
47 Correct 89 ms 15772 KB Correct
48 Correct 89 ms 12296 KB Correct
49 Correct 80 ms 14688 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 88 ms 8096 KB Correct
2 Correct 82 ms 7948 KB Correct
3 Correct 81 ms 7968 KB Correct
4 Correct 100 ms 11932 KB Correct
5 Correct 156 ms 11100 KB Correct
6 Correct 170 ms 11704 KB Correct
7 Correct 77 ms 7576 KB Correct
8 Correct 72 ms 7580 KB Correct
9 Correct 79 ms 7580 KB Correct
10 Correct 77 ms 7772 KB Correct
11 Correct 77 ms 7496 KB Correct
12 Correct 76 ms 7580 KB Correct
13 Correct 83 ms 7756 KB Correct
14 Correct 60 ms 5884 KB Correct
15 Correct 57 ms 6064 KB Correct
16 Correct 76 ms 7588 KB Correct
17 Correct 76 ms 7588 KB Correct
18 Correct 75 ms 7584 KB Correct
19 Correct 78 ms 7752 KB Correct
20 Correct 57 ms 5884 KB Correct
21 Correct 54 ms 6052 KB Correct
22 Correct 58 ms 5988 KB Correct
23 Correct 55 ms 5904 KB Correct
24 Correct 56 ms 5796 KB Correct
25 Correct 60 ms 5968 KB Correct
26 Correct 83 ms 8036 KB Correct
27 Correct 78 ms 8096 KB Correct
28 Correct 81 ms 7960 KB Correct
29 Correct 80 ms 7764 KB Correct
30 Correct 80 ms 8288 KB Correct
31 Correct 73 ms 7836 KB Correct
32 Correct 87 ms 8064 KB Correct
33 Correct 73 ms 7748 KB Correct
34 Correct 86 ms 7916 KB Correct
35 Correct 88 ms 7844 KB Correct
36 Correct 83 ms 7836 KB Correct
37 Correct 70 ms 8028 KB Correct
38 Correct 84 ms 7836 KB Correct
39 Correct 77 ms 8092 KB Correct
40 Correct 81 ms 7780 KB Correct
41 Correct 79 ms 7848 KB Correct
42 Correct 88 ms 7932 KB Correct
43 Correct 81 ms 7792 KB Correct
44 Correct 84 ms 7928 KB Correct
45 Correct 79 ms 7964 KB Correct
46 Correct 75 ms 8028 KB Correct
47 Correct 83 ms 7996 KB Correct
48 Correct 78 ms 7840 KB Correct
49 Correct 81 ms 7752 KB Correct
50 Correct 80 ms 8020 KB Correct
51 Correct 83 ms 8028 KB Correct
52 Correct 74 ms 8016 KB Correct
53 Correct 73 ms 7776 KB Correct
54 Correct 84 ms 7956 KB Correct
55 Correct 77 ms 8024 KB Correct
56 Correct 82 ms 8284 KB Correct
57 Correct 81 ms 8092 KB Correct
58 Correct 79 ms 8016 KB Correct
59 Correct 81 ms 8212 KB Correct
60 Correct 76 ms 8096 KB Correct
61 Correct 84 ms 8016 KB Correct
62 Correct 84 ms 8164 KB Correct
63 Correct 81 ms 8092 KB Correct
64 Correct 87 ms 8008 KB Correct
65 Correct 77 ms 8024 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1016 KB Correct
2 Correct 195 ms 15200 KB Correct
3 Correct 221 ms 16156 KB Correct
4 Correct 100 ms 16248 KB Correct
5 Correct 113 ms 15264 KB Correct
6 Correct 216 ms 16212 KB Correct
7 Correct 78 ms 14412 KB Correct
8 Correct 81 ms 13400 KB Correct
9 Correct 205 ms 15380 KB Correct
10 Correct 218 ms 16728 KB Correct
11 Correct 164 ms 14968 KB Correct
12 Correct 106 ms 16024 KB Correct
13 Correct 279 ms 15088 KB Correct
14 Correct 80 ms 12896 KB Correct
15 Correct 82 ms 12700 KB Correct
16 Correct 198 ms 15964 KB Correct
17 Correct 241 ms 16804 KB Correct
18 Correct 135 ms 13660 KB Correct
19 Correct 98 ms 13932 KB Correct
20 Correct 181 ms 13172 KB Correct
21 Correct 81 ms 14172 KB Correct
22 Correct 90 ms 13920 KB Correct
23 Correct 210 ms 15748 KB Correct
24 Correct 231 ms 16468 KB Correct
25 Correct 95 ms 14184 KB Correct
26 Correct 101 ms 15204 KB Correct
27 Correct 90 ms 13940 KB Correct
28 Correct 77 ms 13392 KB Correct
29 Correct 82 ms 12364 KB Correct
30 Correct 214 ms 16844 KB Correct
31 Correct 225 ms 15184 KB Correct
32 Correct 91 ms 15192 KB Correct
33 Correct 265 ms 14596 KB Correct
34 Correct 275 ms 15036 KB Correct
35 Correct 90 ms 12656 KB Correct
36 Correct 84 ms 13224 KB Correct
37 Correct 228 ms 15908 KB Correct
38 Correct 219 ms 16708 KB Correct
39 Correct 270 ms 15560 KB Correct
40 Correct 149 ms 15968 KB Correct
41 Correct 213 ms 15052 KB Correct
42 Correct 83 ms 13216 KB Correct
43 Correct 81 ms 14168 KB Correct
44 Correct 216 ms 15896 KB Correct
45 Correct 222 ms 14904 KB Correct
46 Correct 88 ms 14504 KB Correct
47 Correct 93 ms 15144 KB Correct
48 Correct 89 ms 15772 KB Correct
49 Correct 89 ms 12296 KB Correct
50 Correct 80 ms 14688 KB Correct
51 Correct 88 ms 8096 KB Correct
52 Correct 82 ms 7948 KB Correct
53 Correct 81 ms 7968 KB Correct
54 Correct 100 ms 11932 KB Correct
55 Correct 156 ms 11100 KB Correct
56 Correct 170 ms 11704 KB Correct
57 Correct 77 ms 7576 KB Correct
58 Correct 72 ms 7580 KB Correct
59 Correct 79 ms 7580 KB Correct
60 Correct 77 ms 7772 KB Correct
61 Correct 77 ms 7496 KB Correct
62 Correct 76 ms 7580 KB Correct
63 Correct 83 ms 7756 KB Correct
64 Correct 60 ms 5884 KB Correct
65 Correct 57 ms 6064 KB Correct
66 Correct 76 ms 7588 KB Correct
67 Correct 76 ms 7588 KB Correct
68 Correct 75 ms 7584 KB Correct
69 Correct 78 ms 7752 KB Correct
70 Correct 57 ms 5884 KB Correct
71 Correct 54 ms 6052 KB Correct
72 Correct 58 ms 5988 KB Correct
73 Correct 55 ms 5904 KB Correct
74 Correct 56 ms 5796 KB Correct
75 Correct 60 ms 5968 KB Correct
76 Correct 83 ms 8036 KB Correct
77 Correct 78 ms 8096 KB Correct
78 Correct 81 ms 7960 KB Correct
79 Correct 80 ms 7764 KB Correct
80 Correct 80 ms 8288 KB Correct
81 Correct 73 ms 7836 KB Correct
82 Correct 87 ms 8064 KB Correct
83 Correct 73 ms 7748 KB Correct
84 Correct 86 ms 7916 KB Correct
85 Correct 88 ms 7844 KB Correct
86 Correct 83 ms 7836 KB Correct
87 Correct 70 ms 8028 KB Correct
88 Correct 84 ms 7836 KB Correct
89 Correct 77 ms 8092 KB Correct
90 Correct 81 ms 7780 KB Correct
91 Correct 79 ms 7848 KB Correct
92 Correct 88 ms 7932 KB Correct
93 Correct 81 ms 7792 KB Correct
94 Correct 84 ms 7928 KB Correct
95 Correct 79 ms 7964 KB Correct
96 Correct 75 ms 8028 KB Correct
97 Correct 83 ms 7996 KB Correct
98 Correct 78 ms 7840 KB Correct
99 Correct 81 ms 7752 KB Correct
100 Correct 80 ms 8020 KB Correct
101 Correct 83 ms 8028 KB Correct
102 Correct 74 ms 8016 KB Correct
103 Correct 73 ms 7776 KB Correct
104 Correct 84 ms 7956 KB Correct
105 Correct 77 ms 8024 KB Correct
106 Correct 82 ms 8284 KB Correct
107 Correct 81 ms 8092 KB Correct
108 Correct 79 ms 8016 KB Correct
109 Correct 81 ms 8212 KB Correct
110 Correct 76 ms 8096 KB Correct
111 Correct 84 ms 8016 KB Correct
112 Correct 84 ms 8164 KB Correct
113 Correct 81 ms 8092 KB Correct
114 Correct 87 ms 8008 KB Correct
115 Correct 77 ms 8024 KB Correct
116 Correct 87 ms 8016 KB Correct
117 Correct 95 ms 8032 KB Correct
118 Correct 81 ms 7952 KB Correct
119 Correct 84 ms 8104 KB Correct
120 Correct 88 ms 8016 KB Correct
121 Correct 83 ms 8092 KB Correct
122 Correct 91 ms 7952 KB Correct
123 Correct 89 ms 12116 KB Correct
124 Correct 141 ms 11272 KB Correct
125 Correct 161 ms 11624 KB Correct
126 Correct 77 ms 7584 KB Correct
127 Correct 73 ms 7496 KB Correct
128 Correct 79 ms 7688 KB Correct
129 Correct 76 ms 7596 KB Correct
130 Correct 80 ms 7584 KB Correct
131 Correct 83 ms 7660 KB Correct
132 Correct 77 ms 7520 KB Correct
133 Correct 61 ms 5788 KB Correct
134 Correct 59 ms 5636 KB Correct
135 Correct 83 ms 7580 KB Correct
136 Correct 77 ms 7768 KB Correct
137 Correct 77 ms 7760 KB Correct
138 Correct 79 ms 7712 KB Correct
139 Correct 62 ms 5900 KB Correct
140 Correct 51 ms 5784 KB Correct
141 Correct 55 ms 5796 KB Correct
142 Correct 60 ms 5968 KB Correct
143 Correct 61 ms 5796 KB Correct
144 Correct 56 ms 5716 KB Correct
145 Correct 90 ms 7768 KB Correct
146 Correct 71 ms 7836 KB Correct
147 Correct 90 ms 7768 KB Correct
148 Correct 91 ms 8012 KB Correct
149 Correct 79 ms 7956 KB Correct
150 Correct 96 ms 7836 KB Correct
151 Correct 84 ms 8096 KB Correct
152 Correct 80 ms 7768 KB Correct
153 Correct 83 ms 8024 KB Correct
154 Correct 88 ms 8012 KB Correct
155 Correct 84 ms 7820 KB Correct
156 Correct 83 ms 8008 KB Correct
157 Correct 87 ms 7956 KB Correct
158 Correct 93 ms 7900 KB Correct
159 Correct 87 ms 7772 KB Correct
160 Correct 84 ms 7952 KB Correct
161 Correct 94 ms 7752 KB Correct
162 Correct 83 ms 7844 KB Correct
163 Correct 98 ms 7840 KB Correct
164 Correct 81 ms 8012 KB Correct
165 Correct 84 ms 8332 KB Correct
166 Correct 88 ms 7932 KB Correct
167 Correct 92 ms 7948 KB Correct
168 Correct 84 ms 7892 KB Correct
169 Correct 92 ms 7836 KB Correct
170 Correct 84 ms 7948 KB Correct
171 Correct 87 ms 7844 KB Correct
172 Correct 96 ms 8044 KB Correct
173 Correct 71 ms 8024 KB Correct
174 Correct 83 ms 7936 KB Correct
175 Correct 73 ms 8008 KB Correct
176 Correct 80 ms 8020 KB Correct
177 Correct 80 ms 7928 KB Correct
178 Correct 81 ms 8008 KB Correct
179 Correct 80 ms 7948 KB Correct
180 Correct 84 ms 7920 KB Correct
181 Correct 81 ms 8092 KB Correct
182 Correct 70 ms 8172 KB Correct
183 Correct 81 ms 8040 KB Correct
184 Correct 80 ms 8024 KB Correct
185 Correct 213 ms 14964 KB Correct
186 Correct 230 ms 16008 KB Correct
187 Correct 113 ms 16208 KB Correct
188 Correct 113 ms 15400 KB Correct
189 Correct 225 ms 16396 KB Correct
190 Correct 91 ms 14280 KB Correct
191 Correct 95 ms 13472 KB Correct
192 Correct 215 ms 15124 KB Correct
193 Correct 215 ms 16840 KB Correct
194 Correct 165 ms 15024 KB Correct
195 Correct 110 ms 16116 KB Correct
196 Correct 289 ms 15088 KB Correct
197 Correct 91 ms 12644 KB Correct
198 Correct 95 ms 12556 KB Correct
199 Correct 196 ms 16208 KB Correct
200 Correct 231 ms 16796 KB Correct
201 Correct 144 ms 13876 KB Correct
202 Correct 98 ms 13912 KB Correct
203 Correct 151 ms 13088 KB Correct
204 Correct 94 ms 14100 KB Correct
205 Correct 93 ms 13900 KB Correct
206 Correct 225 ms 15656 KB Correct
207 Correct 201 ms 16140 KB Correct
208 Correct 95 ms 14156 KB Correct
209 Correct 94 ms 15116 KB Correct
210 Correct 94 ms 13848 KB Correct
211 Correct 79 ms 13408 KB Correct
212 Correct 83 ms 12560 KB Correct
213 Correct 240 ms 16828 KB Correct
214 Correct 212 ms 14928 KB Correct
215 Correct 99 ms 15192 KB Correct
216 Correct 249 ms 14596 KB Correct
217 Correct 224 ms 15040 KB Correct
218 Correct 90 ms 12700 KB Correct
219 Correct 88 ms 13144 KB Correct
220 Correct 226 ms 16032 KB Correct
221 Correct 209 ms 16712 KB Correct
222 Correct 275 ms 15556 KB Correct
223 Correct 161 ms 16288 KB Correct
224 Correct 222 ms 15260 KB Correct
225 Correct 89 ms 13148 KB Correct
226 Correct 91 ms 14176 KB Correct
227 Correct 234 ms 16224 KB Correct
228 Correct 213 ms 14972 KB Correct
229 Correct 92 ms 14240 KB Correct
230 Correct 86 ms 15260 KB Correct
231 Correct 97 ms 15760 KB Correct
232 Correct 75 ms 12364 KB Correct
233 Correct 79 ms 14692 KB Correct
234 Correct 89 ms 11292 KB Correct
235 Correct 102 ms 10632 KB Correct
236 Correct 65 ms 5800 KB Correct
237 Correct 62 ms 6132 KB Correct
238 Correct 61 ms 5888 KB Correct
239 Correct 47 ms 4552 KB Correct
240 Correct 76 ms 7964 KB Correct
241 Correct 79 ms 7840 KB Correct
242 Correct 84 ms 7836 KB Correct
243 Correct 88 ms 8028 KB Correct
244 Correct 80 ms 7776 KB Correct
245 Correct 86 ms 8024 KB Correct
246 Correct 83 ms 7756 KB Correct
247 Correct 79 ms 7836 KB Correct
248 Correct 83 ms 7868 KB Correct
249 Correct 82 ms 7948 KB Correct
250 Correct 87 ms 8032 KB Correct
251 Correct 75 ms 8024 KB Correct
252 Correct 76 ms 8092 KB Correct
253 Correct 82 ms 7844 KB Correct
254 Correct 86 ms 7844 KB Correct
255 Correct 78 ms 7836 KB Correct
256 Correct 81 ms 7864 KB Correct
257 Correct 78 ms 7712 KB Correct
258 Correct 73 ms 7836 KB Correct
259 Correct 86 ms 7840 KB Correct
260 Correct 83 ms 7900 KB Correct
261 Correct 86 ms 8028 KB Correct
262 Correct 80 ms 8040 KB Correct
263 Correct 84 ms 7772 KB Correct
264 Correct 75 ms 8016 KB Correct
265 Correct 53 ms 5788 KB Correct
266 Correct 64 ms 5868 KB Correct
267 Correct 57 ms 5728 KB Correct
268 Correct 55 ms 5796 KB Correct
269 Correct 54 ms 5792 KB Correct
270 Correct 60 ms 5884 KB Correct
271 Correct 62 ms 5872 KB Correct
272 Correct 57 ms 5876 KB Correct
273 Correct 62 ms 5884 KB Correct
274 Correct 56 ms 6060 KB Correct
275 Correct 65 ms 5888 KB Correct
276 Correct 54 ms 6048 KB Correct
277 Correct 68 ms 5708 KB Correct
278 Correct 62 ms 5884 KB Correct
279 Correct 55 ms 5888 KB Correct
280 Correct 80 ms 8004 KB Correct
281 Correct 82 ms 8280 KB Correct
282 Correct 79 ms 8220 KB Correct
283 Correct 84 ms 7988 KB Correct
284 Correct 83 ms 8028 KB Correct
285 Correct 75 ms 8172 KB Correct
286 Correct 86 ms 8092 KB Correct
287 Correct 79 ms 8052 KB Correct
288 Correct 89 ms 8032 KB Correct
289 Correct 82 ms 8272 KB Correct