Submission #1040688

# Submission time Handle Problem Language Result Execution time Memory
1040688 2024-08-01T08:29:35 Z ㅇㅇ(#11044) The Ties That Guide Us (CEOI23_incursion) C++17
100 / 100
278 ms 16404 KB
#include "incursion.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> G[45009];
int _N, _S[45009], C[45009], V[45009], P[45009];

void dfs(int x, int p) {
    _S[x] = 1;
    int mx = 0;
    for(auto it: G[x]) if(it != p) {
        dfs(it, x);
        _S[x] += _S[it];
        mx = max(mx, _S[it]);
    }
    if(x == p) {
        C[x] = 0;
        return;
    }
    int r = _N - _S[x];
    mx = max(mx, r);
    if(r == mx) C[x] = 1;
    else C[x] = 0;
}

vector<int> mark(vector<pair<int, int>> F, int safe) {
    _N = F.size() + 1;
    for(int i=1; i<=_N; i++) G[i].clear();
    for(auto [u, v]: F) {
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs(safe, safe);
    vector<int> ret(_N);
    for(int i=1; i<=_N; i++) ret[i-1] = C[i];
    return ret;
}

void go(int x, int p) {
    P[x] = p;
    _S[x] = 1;
    for(auto it: G[x]) if(it != p) {
        go(it, x);
        _S[x] += _S[it];
    }
}

void fnd(int x, int t) {
    V[x] = 1;
    vector<pair<int, int>> A;
    for(auto it: G[x]) if(it != P[x]) A.push_back({_S[it], it});
    if(x != P[x]) A.push_back({_N - _S[x], P[x]});
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    if(t == 1) {
        int c = 0;
        for(auto [s, it]: A) if(s == A[0].first) ++c;
        if(c == 1) return fnd(A[0].second, visit(A[0].second));
        else {
            for(auto [s, it]: A) if(!V[it] && s == A[0].first) {
                if(visit(it) == 1) visit(x);
                else return fnd(it, 0);
            }
        }
    }
    if(t == 0) {
        for(auto [s, it]: A) if(!V[it] && s < A[0].first) {
            if(visit(it) == 1) visit(x);
            else return fnd(it, 0);
        }
    }
}

void locate(vector<pair<int, int>> F, int curr, int t) {
    _N = F.size() + 1;
    for(int i=1; i<=_N; i++) G[i].clear();
    for(auto [u, v]: F) {
        G[u].push_back(v);
        G[v].push_back(u);
    }
    go(curr, curr);
    fnd(curr, t);
    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 1 ms 2816 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 193 ms 15088 KB Correct
2 Correct 175 ms 15020 KB Correct
3 Correct 94 ms 14976 KB Correct
4 Correct 101 ms 12668 KB Correct
5 Correct 194 ms 14236 KB Correct
6 Correct 69 ms 11424 KB Correct
7 Correct 57 ms 11516 KB Correct
8 Correct 194 ms 15124 KB Correct
9 Correct 195 ms 15076 KB Correct
10 Correct 137 ms 13292 KB Correct
11 Correct 91 ms 13432 KB Correct
12 Correct 272 ms 16124 KB Correct
13 Correct 75 ms 11532 KB Correct
14 Correct 74 ms 11420 KB Correct
15 Correct 176 ms 15076 KB Correct
16 Correct 179 ms 15080 KB Correct
17 Correct 109 ms 13284 KB Correct
18 Correct 88 ms 14412 KB Correct
19 Correct 134 ms 14116 KB Correct
20 Correct 74 ms 11348 KB Correct
21 Correct 73 ms 11124 KB Correct
22 Correct 184 ms 15184 KB Correct
23 Correct 180 ms 15036 KB Correct
24 Correct 86 ms 13260 KB Correct
25 Correct 73 ms 14468 KB Correct
26 Correct 80 ms 13084 KB Correct
27 Correct 72 ms 11392 KB Correct
28 Correct 67 ms 11380 KB Correct
29 Correct 195 ms 14968 KB Correct
30 Correct 180 ms 14936 KB Correct
31 Correct 74 ms 12164 KB Correct
32 Correct 212 ms 15600 KB Correct
33 Correct 215 ms 15252 KB Correct
34 Correct 65 ms 11396 KB Correct
35 Correct 64 ms 11420 KB Correct
36 Correct 179 ms 15220 KB Correct
37 Correct 183 ms 15052 KB Correct
38 Correct 209 ms 15296 KB Correct
39 Correct 115 ms 14000 KB Correct
40 Correct 177 ms 14260 KB Correct
41 Correct 72 ms 11388 KB Correct
42 Correct 68 ms 11428 KB Correct
43 Correct 195 ms 15392 KB Correct
44 Correct 193 ms 15216 KB Correct
45 Correct 66 ms 13700 KB Correct
46 Correct 71 ms 13984 KB Correct
47 Correct 79 ms 13188 KB Correct
48 Correct 69 ms 11536 KB Correct
49 Correct 69 ms 11420 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 8172 KB Correct
2 Correct 57 ms 8104 KB Correct
3 Correct 70 ms 8060 KB Correct
4 Correct 78 ms 10932 KB Correct
5 Correct 107 ms 11160 KB Correct
6 Correct 138 ms 12408 KB Correct
7 Correct 61 ms 7804 KB Correct
8 Correct 70 ms 7776 KB Correct
9 Correct 68 ms 8024 KB Correct
10 Correct 60 ms 7844 KB Correct
11 Correct 75 ms 7784 KB Correct
12 Correct 69 ms 7836 KB Correct
13 Correct 61 ms 7836 KB Correct
14 Correct 50 ms 6556 KB Correct
15 Correct 49 ms 6704 KB Correct
16 Correct 62 ms 7800 KB Correct
17 Correct 62 ms 7808 KB Correct
18 Correct 61 ms 7804 KB Correct
19 Correct 67 ms 7700 KB Correct
20 Correct 45 ms 6444 KB Correct
21 Correct 45 ms 6616 KB Correct
22 Correct 49 ms 6576 KB Correct
23 Correct 46 ms 6568 KB Correct
24 Correct 47 ms 6708 KB Correct
25 Correct 49 ms 6700 KB Correct
26 Correct 64 ms 7840 KB Correct
27 Correct 69 ms 8068 KB Correct
28 Correct 64 ms 8064 KB Correct
29 Correct 66 ms 7804 KB Correct
30 Correct 64 ms 8100 KB Correct
31 Correct 67 ms 7840 KB Correct
32 Correct 61 ms 8080 KB Correct
33 Correct 66 ms 7848 KB Correct
34 Correct 67 ms 7804 KB Correct
35 Correct 73 ms 8324 KB Correct
36 Correct 65 ms 8296 KB Correct
37 Correct 68 ms 8024 KB Correct
38 Correct 61 ms 7796 KB Correct
39 Correct 78 ms 7812 KB Correct
40 Correct 65 ms 8104 KB Correct
41 Correct 64 ms 8084 KB Correct
42 Correct 71 ms 8296 KB Correct
43 Correct 67 ms 8056 KB Correct
44 Correct 71 ms 7804 KB Correct
45 Correct 80 ms 8028 KB Correct
46 Correct 70 ms 8296 KB Correct
47 Correct 64 ms 8356 KB Correct
48 Correct 68 ms 7716 KB Correct
49 Correct 64 ms 7808 KB Correct
50 Correct 74 ms 8064 KB Correct
51 Correct 64 ms 8064 KB Correct
52 Correct 70 ms 8104 KB Correct
53 Correct 62 ms 7812 KB Correct
54 Correct 62 ms 7808 KB Correct
55 Correct 70 ms 7964 KB Correct
56 Correct 62 ms 8056 KB Correct
57 Correct 66 ms 8032 KB Correct
58 Correct 61 ms 8064 KB Correct
59 Correct 68 ms 8072 KB Correct
60 Correct 64 ms 7704 KB Correct
61 Correct 68 ms 8072 KB Correct
62 Correct 64 ms 8040 KB Correct
63 Correct 64 ms 7940 KB Correct
64 Correct 66 ms 7848 KB Correct
65 Correct 56 ms 7844 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2816 KB Correct
2 Correct 193 ms 15088 KB Correct
3 Correct 175 ms 15020 KB Correct
4 Correct 94 ms 14976 KB Correct
5 Correct 101 ms 12668 KB Correct
6 Correct 194 ms 14236 KB Correct
7 Correct 69 ms 11424 KB Correct
8 Correct 57 ms 11516 KB Correct
9 Correct 194 ms 15124 KB Correct
10 Correct 195 ms 15076 KB Correct
11 Correct 137 ms 13292 KB Correct
12 Correct 91 ms 13432 KB Correct
13 Correct 272 ms 16124 KB Correct
14 Correct 75 ms 11532 KB Correct
15 Correct 74 ms 11420 KB Correct
16 Correct 176 ms 15076 KB Correct
17 Correct 179 ms 15080 KB Correct
18 Correct 109 ms 13284 KB Correct
19 Correct 88 ms 14412 KB Correct
20 Correct 134 ms 14116 KB Correct
21 Correct 74 ms 11348 KB Correct
22 Correct 73 ms 11124 KB Correct
23 Correct 184 ms 15184 KB Correct
24 Correct 180 ms 15036 KB Correct
25 Correct 86 ms 13260 KB Correct
26 Correct 73 ms 14468 KB Correct
27 Correct 80 ms 13084 KB Correct
28 Correct 72 ms 11392 KB Correct
29 Correct 67 ms 11380 KB Correct
30 Correct 195 ms 14968 KB Correct
31 Correct 180 ms 14936 KB Correct
32 Correct 74 ms 12164 KB Correct
33 Correct 212 ms 15600 KB Correct
34 Correct 215 ms 15252 KB Correct
35 Correct 65 ms 11396 KB Correct
36 Correct 64 ms 11420 KB Correct
37 Correct 179 ms 15220 KB Correct
38 Correct 183 ms 15052 KB Correct
39 Correct 209 ms 15296 KB Correct
40 Correct 115 ms 14000 KB Correct
41 Correct 177 ms 14260 KB Correct
42 Correct 72 ms 11388 KB Correct
43 Correct 68 ms 11428 KB Correct
44 Correct 195 ms 15392 KB Correct
45 Correct 193 ms 15216 KB Correct
46 Correct 66 ms 13700 KB Correct
47 Correct 71 ms 13984 KB Correct
48 Correct 79 ms 13188 KB Correct
49 Correct 69 ms 11536 KB Correct
50 Correct 69 ms 11420 KB Correct
51 Correct 73 ms 8172 KB Correct
52 Correct 57 ms 8104 KB Correct
53 Correct 70 ms 8060 KB Correct
54 Correct 78 ms 10932 KB Correct
55 Correct 107 ms 11160 KB Correct
56 Correct 138 ms 12408 KB Correct
57 Correct 61 ms 7804 KB Correct
58 Correct 70 ms 7776 KB Correct
59 Correct 68 ms 8024 KB Correct
60 Correct 60 ms 7844 KB Correct
61 Correct 75 ms 7784 KB Correct
62 Correct 69 ms 7836 KB Correct
63 Correct 61 ms 7836 KB Correct
64 Correct 50 ms 6556 KB Correct
65 Correct 49 ms 6704 KB Correct
66 Correct 62 ms 7800 KB Correct
67 Correct 62 ms 7808 KB Correct
68 Correct 61 ms 7804 KB Correct
69 Correct 67 ms 7700 KB Correct
70 Correct 45 ms 6444 KB Correct
71 Correct 45 ms 6616 KB Correct
72 Correct 49 ms 6576 KB Correct
73 Correct 46 ms 6568 KB Correct
74 Correct 47 ms 6708 KB Correct
75 Correct 49 ms 6700 KB Correct
76 Correct 64 ms 7840 KB Correct
77 Correct 69 ms 8068 KB Correct
78 Correct 64 ms 8064 KB Correct
79 Correct 66 ms 7804 KB Correct
80 Correct 64 ms 8100 KB Correct
81 Correct 67 ms 7840 KB Correct
82 Correct 61 ms 8080 KB Correct
83 Correct 66 ms 7848 KB Correct
84 Correct 67 ms 7804 KB Correct
85 Correct 73 ms 8324 KB Correct
86 Correct 65 ms 8296 KB Correct
87 Correct 68 ms 8024 KB Correct
88 Correct 61 ms 7796 KB Correct
89 Correct 78 ms 7812 KB Correct
90 Correct 65 ms 8104 KB Correct
91 Correct 64 ms 8084 KB Correct
92 Correct 71 ms 8296 KB Correct
93 Correct 67 ms 8056 KB Correct
94 Correct 71 ms 7804 KB Correct
95 Correct 80 ms 8028 KB Correct
96 Correct 70 ms 8296 KB Correct
97 Correct 64 ms 8356 KB Correct
98 Correct 68 ms 7716 KB Correct
99 Correct 64 ms 7808 KB Correct
100 Correct 74 ms 8064 KB Correct
101 Correct 64 ms 8064 KB Correct
102 Correct 70 ms 8104 KB Correct
103 Correct 62 ms 7812 KB Correct
104 Correct 62 ms 7808 KB Correct
105 Correct 70 ms 7964 KB Correct
106 Correct 62 ms 8056 KB Correct
107 Correct 66 ms 8032 KB Correct
108 Correct 61 ms 8064 KB Correct
109 Correct 68 ms 8072 KB Correct
110 Correct 64 ms 7704 KB Correct
111 Correct 68 ms 8072 KB Correct
112 Correct 64 ms 8040 KB Correct
113 Correct 64 ms 7940 KB Correct
114 Correct 66 ms 7848 KB Correct
115 Correct 56 ms 7844 KB Correct
116 Correct 67 ms 8352 KB Correct
117 Correct 78 ms 8548 KB Correct
118 Correct 71 ms 8288 KB Correct
119 Correct 68 ms 8356 KB Correct
120 Correct 73 ms 8092 KB Correct
121 Correct 76 ms 8004 KB Correct
122 Correct 66 ms 8100 KB Correct
123 Correct 81 ms 10900 KB Correct
124 Correct 126 ms 11284 KB Correct
125 Correct 142 ms 12208 KB Correct
126 Correct 66 ms 7748 KB Correct
127 Correct 69 ms 7804 KB Correct
128 Correct 64 ms 7812 KB Correct
129 Correct 64 ms 7840 KB Correct
130 Correct 61 ms 7836 KB Correct
131 Correct 65 ms 7792 KB Correct
132 Correct 68 ms 7840 KB Correct
133 Correct 55 ms 6700 KB Correct
134 Correct 52 ms 6572 KB Correct
135 Correct 66 ms 7692 KB Correct
136 Correct 65 ms 7800 KB Correct
137 Correct 67 ms 7792 KB Correct
138 Correct 64 ms 7756 KB Correct
139 Correct 49 ms 6696 KB Correct
140 Correct 44 ms 6572 KB Correct
141 Correct 50 ms 6696 KB Correct
142 Correct 50 ms 6428 KB Correct
143 Correct 56 ms 6684 KB Correct
144 Correct 53 ms 6568 KB Correct
145 Correct 82 ms 8028 KB Correct
146 Correct 71 ms 7844 KB Correct
147 Correct 66 ms 7812 KB Correct
148 Correct 69 ms 7804 KB Correct
149 Correct 69 ms 8284 KB Correct
150 Correct 69 ms 7816 KB Correct
151 Correct 73 ms 8332 KB Correct
152 Correct 71 ms 7808 KB Correct
153 Correct 69 ms 8076 KB Correct
154 Correct 72 ms 8288 KB Correct
155 Correct 61 ms 8068 KB Correct
156 Correct 75 ms 7780 KB Correct
157 Correct 71 ms 7844 KB Correct
158 Correct 69 ms 7836 KB Correct
159 Correct 76 ms 7840 KB Correct
160 Correct 68 ms 8052 KB Correct
161 Correct 76 ms 8056 KB Correct
162 Correct 68 ms 7928 KB Correct
163 Correct 70 ms 8040 KB Correct
164 Correct 72 ms 8064 KB Correct
165 Correct 65 ms 8096 KB Correct
166 Correct 78 ms 8464 KB Correct
167 Correct 74 ms 8068 KB Correct
168 Correct 63 ms 7840 KB Correct
169 Correct 62 ms 8024 KB Correct
170 Correct 79 ms 8024 KB Correct
171 Correct 72 ms 8180 KB Correct
172 Correct 71 ms 7644 KB Correct
173 Correct 81 ms 8080 KB Correct
174 Correct 72 ms 7820 KB Correct
175 Correct 79 ms 7828 KB Correct
176 Correct 65 ms 8068 KB Correct
177 Correct 69 ms 8068 KB Correct
178 Correct 71 ms 8060 KB Correct
179 Correct 68 ms 8040 KB Correct
180 Correct 63 ms 8108 KB Correct
181 Correct 71 ms 8164 KB Correct
182 Correct 74 ms 8060 KB Correct
183 Correct 71 ms 8060 KB Correct
184 Correct 57 ms 7800 KB Correct
185 Correct 186 ms 14960 KB Correct
186 Correct 170 ms 15052 KB Correct
187 Correct 87 ms 14716 KB Correct
188 Correct 92 ms 12904 KB Correct
189 Correct 169 ms 14124 KB Correct
190 Correct 60 ms 11388 KB Correct
191 Correct 77 ms 11340 KB Correct
192 Correct 179 ms 15092 KB Correct
193 Correct 194 ms 15052 KB Correct
194 Correct 127 ms 13044 KB Correct
195 Correct 93 ms 13728 KB Correct
196 Correct 278 ms 16404 KB Correct
197 Correct 71 ms 11376 KB Correct
198 Correct 79 ms 11420 KB Correct
199 Correct 191 ms 14888 KB Correct
200 Correct 197 ms 15352 KB Correct
201 Correct 109 ms 13220 KB Correct
202 Correct 100 ms 14088 KB Correct
203 Correct 143 ms 13980 KB Correct
204 Correct 68 ms 11420 KB Correct
205 Correct 61 ms 11420 KB Correct
206 Correct 195 ms 15008 KB Correct
207 Correct 180 ms 15160 KB Correct
208 Correct 89 ms 13004 KB Correct
209 Correct 78 ms 14492 KB Correct
210 Correct 76 ms 13148 KB Correct
211 Correct 69 ms 11420 KB Correct
212 Correct 62 ms 11400 KB Correct
213 Correct 195 ms 15032 KB Correct
214 Correct 180 ms 15108 KB Correct
215 Correct 86 ms 12468 KB Correct
216 Correct 243 ms 15516 KB Correct
217 Correct 219 ms 15124 KB Correct
218 Correct 66 ms 11424 KB Correct
219 Correct 80 ms 11296 KB Correct
220 Correct 190 ms 15328 KB Correct
221 Correct 168 ms 15144 KB Correct
222 Correct 206 ms 15368 KB Correct
223 Correct 121 ms 14100 KB Correct
224 Correct 188 ms 14292 KB Correct
225 Correct 74 ms 11368 KB Correct
226 Correct 69 ms 11416 KB Correct
227 Correct 160 ms 15544 KB Correct
228 Correct 176 ms 15260 KB Correct
229 Correct 79 ms 13660 KB Correct
230 Correct 62 ms 13988 KB Correct
231 Correct 72 ms 13460 KB Correct
232 Correct 76 ms 11296 KB Correct
233 Correct 70 ms 11420 KB Correct
234 Correct 78 ms 11424 KB Correct
235 Correct 90 ms 10504 KB Correct
236 Correct 50 ms 6696 KB Correct
237 Correct 50 ms 6680 KB Correct
238 Correct 50 ms 6568 KB Correct
239 Correct 37 ms 5584 KB Correct
240 Correct 78 ms 7864 KB Correct
241 Correct 66 ms 7920 KB Correct
242 Correct 71 ms 7772 KB Correct
243 Correct 81 ms 8100 KB Correct
244 Correct 63 ms 7816 KB Correct
245 Correct 70 ms 7820 KB Correct
246 Correct 74 ms 7860 KB Correct
247 Correct 73 ms 7760 KB Correct
248 Correct 71 ms 8032 KB Correct
249 Correct 73 ms 7824 KB Correct
250 Correct 65 ms 7780 KB Correct
251 Correct 69 ms 7792 KB Correct
252 Correct 63 ms 7900 KB Correct
253 Correct 76 ms 7880 KB Correct
254 Correct 69 ms 8288 KB Correct
255 Correct 68 ms 7844 KB Correct
256 Correct 76 ms 7760 KB Correct
257 Correct 76 ms 7880 KB Correct
258 Correct 86 ms 8292 KB Correct
259 Correct 90 ms 8100 KB Correct
260 Correct 67 ms 7840 KB Correct
261 Correct 68 ms 7836 KB Correct
262 Correct 67 ms 7784 KB Correct
263 Correct 70 ms 8056 KB Correct
264 Correct 70 ms 7812 KB Correct
265 Correct 58 ms 6712 KB Correct
266 Correct 48 ms 6704 KB Correct
267 Correct 52 ms 6428 KB Correct
268 Correct 46 ms 6536 KB Correct
269 Correct 45 ms 6556 KB Correct
270 Correct 47 ms 6576 KB Correct
271 Correct 49 ms 6688 KB Correct
272 Correct 50 ms 6724 KB Correct
273 Correct 56 ms 6568 KB Correct
274 Correct 53 ms 6688 KB Correct
275 Correct 48 ms 6576 KB Correct
276 Correct 52 ms 6604 KB Correct
277 Correct 52 ms 6680 KB Correct
278 Correct 49 ms 6576 KB Correct
279 Correct 52 ms 6572 KB Correct
280 Correct 74 ms 8036 KB Correct
281 Correct 60 ms 8036 KB Correct
282 Correct 80 ms 8036 KB Correct
283 Correct 64 ms 8016 KB Correct
284 Correct 70 ms 8012 KB Correct
285 Correct 73 ms 8020 KB Correct
286 Correct 66 ms 8072 KB Correct
287 Correct 69 ms 8016 KB Correct
288 Correct 71 ms 8048 KB Correct
289 Correct 80 ms 8004 KB Correct