Submission #1065097

# Submission time Handle Problem Language Result Execution time Memory
1065097 2024-08-18T22:36:49 Z beaconmc The Ties That Guide Us (CEOI23_incursion) C++17
100 / 100
287 ms 15800 KB
#include "incursion.h"

#include <bits/stdc++.h>
 
typedef int ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
 
using namespace std;



ll sub[50000];
vector<ll> edges[50000];
ll par[50000];
ll visited[50000];
ll depth[50000];
ll unsure[50000];
ll n;



void dfs(ll a, ll p, ll d){
    depth[a] = d;
    par[a] = p;
    sub[a] = 1;
    for (auto&i : edges[a]){
        if (i != p) dfs(i,a,d+1), sub[a] += sub[i];
    }
}

ll centfind(ll a, ll p){
    visited[a] = 1;
    for (auto&i : edges[a]){
        if (i!=p && sub[i] > n/2) return centfind(i, a);
    }
    return a;
}





vector<int> mark(std::vector<std::pair<int, int>> F, int safe) {
    n = (ll)F.size()+1;
    vector<int> ties(n);

    FOR(i,0,50000) edges[i].clear(), sub[i] = 0, par[i] = -1, depth[i] = 0, visited[i] = 0;

    for (auto&i : F){
        edges[i.first].push_back(i.second);
        edges[i.second].push_back(i.first);
    }
    dfs(1, -1, 0);

    ll cent = centfind(1, -1);
    ll cent2 = cent;
    ll root = -1;
    for (auto&i : edges[cent]){
        if (i != par[cent]){
            root = i;
            dfs(root, -1, 0);
            cent2 = centfind(root, -1);
            if (cent != cent2) break;
        }
    }
    


    dfs(cent, -1, 0);


    FOR(i,0,50000) visited[i] = 0;

    while (safe != -1){
        ties[safe-1] = 1;
        if (safe==cent || safe==cent2) break;
        safe = par[safe];
    }

    return ties;


}

bool cmp(ll a, ll b){
    return sub[a] < sub[b];
}

void locate(std::vector<std::pair<int, int>> F, int curr, int t) {
    n = (ll)F.size()+1;


    FOR(i,0,50000) edges[i].clear(), sub[i] = 0, par[i] = -1, depth[i] = 0, visited[i] = 0;

    for (auto&i : F){
        edges[i.first].push_back(i.second);
        edges[i.second].push_back(i.first);
    }
    dfs(1, -1, 0);

    ll cent = centfind(1, -1);
    ll cent2 = cent;
    ll root = -1;
    for (auto&i : edges[cent]){
        if (i != par[cent]){
            root = i;
            dfs(root, -1, 0);
            cent2 = centfind(root, -1);
            if (cent != cent2) break;
        }
    }
    


    dfs(cent, -1, 0);


    FOR(i,0,50000) visited[i] = 0;


    visited[curr] = 1;

    //cout << cent << endl;

    while (t != 1 && curr != cent){
        t = visit(par[curr]);
        curr = par[curr];
        visited[curr] = 1;
    }
    if (t != 1){
        t = visit(cent2);
        curr = cent2;
        visited[curr] = 1;
    }

    while (1){
        //cout << curr << endl;

        visited[curr] = 1;
        if (t==0 && curr!=cent){
            t = visit(par[curr]);
            curr = par[curr];
            continue;
        }
        sort(edges[curr].begin(), edges[curr].end(), cmp);
        reverse(edges[curr].begin(), edges[curr].end());
        bool done = false;


        for (auto&i : edges[curr]){

            if (i==par[curr]) continue;

            if (!visited[i]){
                visited[i] = true;
                t = visit(i);
                curr = i;
                done = true;
                break;
            }
        }

        if (!done){
            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 4616 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 214 ms 13444 KB Correct
2 Correct 208 ms 13788 KB Correct
3 Correct 105 ms 14832 KB Correct
4 Correct 114 ms 15304 KB Correct
5 Correct 218 ms 15004 KB Correct
6 Correct 75 ms 15008 KB Correct
7 Correct 88 ms 13468 KB Correct
8 Correct 219 ms 14028 KB Correct
9 Correct 203 ms 14748 KB Correct
10 Correct 163 ms 14060 KB Correct
11 Correct 117 ms 15428 KB Correct
12 Correct 287 ms 13916 KB Correct
13 Correct 88 ms 13296 KB Correct
14 Correct 82 ms 13560 KB Correct
15 Correct 239 ms 14544 KB Correct
16 Correct 211 ms 15796 KB Correct
17 Correct 127 ms 13132 KB Correct
18 Correct 97 ms 13468 KB Correct
19 Correct 159 ms 12964 KB Correct
20 Correct 88 ms 14920 KB Correct
21 Correct 90 ms 13740 KB Correct
22 Correct 225 ms 14260 KB Correct
23 Correct 221 ms 14496 KB Correct
24 Correct 107 ms 13876 KB Correct
25 Correct 92 ms 14492 KB Correct
26 Correct 102 ms 13408 KB Correct
27 Correct 91 ms 13816 KB Correct
28 Correct 100 ms 14296 KB Correct
29 Correct 219 ms 14156 KB Correct
30 Correct 222 ms 13324 KB Correct
31 Correct 101 ms 15416 KB Correct
32 Correct 230 ms 14160 KB Correct
33 Correct 256 ms 14400 KB Correct
34 Correct 76 ms 13396 KB Correct
35 Correct 96 ms 13060 KB Correct
36 Correct 238 ms 14308 KB Correct
37 Correct 234 ms 14492 KB Correct
38 Correct 278 ms 14972 KB Correct
39 Correct 151 ms 15528 KB Correct
40 Correct 200 ms 14628 KB Correct
41 Correct 86 ms 14320 KB Correct
42 Correct 95 ms 14160 KB Correct
43 Correct 237 ms 14576 KB Correct
44 Correct 244 ms 12768 KB Correct
45 Correct 100 ms 13828 KB Correct
46 Correct 91 ms 13824 KB Correct
47 Correct 107 ms 14500 KB Correct
48 Correct 81 ms 12900 KB Correct
49 Correct 88 ms 14856 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 9224 KB Correct
2 Correct 87 ms 9372 KB Correct
3 Correct 82 ms 9220 KB Correct
4 Correct 92 ms 12188 KB Correct
5 Correct 131 ms 11532 KB Correct
6 Correct 173 ms 11776 KB Correct
7 Correct 87 ms 8948 KB Correct
8 Correct 96 ms 8772 KB Correct
9 Correct 79 ms 8864 KB Correct
10 Correct 80 ms 8936 KB Correct
11 Correct 81 ms 8868 KB Correct
12 Correct 74 ms 8940 KB Correct
13 Correct 81 ms 8868 KB Correct
14 Correct 55 ms 7840 KB Correct
15 Correct 61 ms 7848 KB Correct
16 Correct 81 ms 8776 KB Correct
17 Correct 82 ms 8864 KB Correct
18 Correct 79 ms 8940 KB Correct
19 Correct 81 ms 8696 KB Correct
20 Correct 54 ms 7828 KB Correct
21 Correct 60 ms 7832 KB Correct
22 Correct 62 ms 7828 KB Correct
23 Correct 56 ms 7840 KB Correct
24 Correct 54 ms 7824 KB Correct
25 Correct 55 ms 7848 KB Correct
26 Correct 84 ms 9120 KB Correct
27 Correct 83 ms 8924 KB Correct
28 Correct 80 ms 8956 KB Correct
29 Correct 81 ms 8856 KB Correct
30 Correct 88 ms 9048 KB Correct
31 Correct 77 ms 8764 KB Correct
32 Correct 88 ms 9120 KB Correct
33 Correct 82 ms 8944 KB Correct
34 Correct 84 ms 8904 KB Correct
35 Correct 87 ms 8780 KB Correct
36 Correct 87 ms 9120 KB Correct
37 Correct 83 ms 8864 KB Correct
38 Correct 89 ms 8940 KB Correct
39 Correct 77 ms 9124 KB Correct
40 Correct 93 ms 9112 KB Correct
41 Correct 77 ms 8940 KB Correct
42 Correct 93 ms 8848 KB Correct
43 Correct 84 ms 9016 KB Correct
44 Correct 89 ms 9048 KB Correct
45 Correct 84 ms 8928 KB Correct
46 Correct 83 ms 8960 KB Correct
47 Correct 86 ms 9120 KB Correct
48 Correct 89 ms 9048 KB Correct
49 Correct 80 ms 8952 KB Correct
50 Correct 90 ms 9288 KB Correct
51 Correct 77 ms 8932 KB Correct
52 Correct 84 ms 8944 KB Correct
53 Correct 81 ms 8940 KB Correct
54 Correct 84 ms 9212 KB Correct
55 Correct 81 ms 8868 KB Correct
56 Correct 82 ms 9208 KB Correct
57 Correct 83 ms 9192 KB Correct
58 Correct 79 ms 9212 KB Correct
59 Correct 87 ms 9204 KB Correct
60 Correct 88 ms 9380 KB Correct
61 Correct 94 ms 9372 KB Correct
62 Correct 86 ms 9372 KB Correct
63 Correct 82 ms 9120 KB Correct
64 Correct 83 ms 9128 KB Correct
65 Correct 73 ms 9240 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4616 KB Correct
2 Correct 214 ms 13444 KB Correct
3 Correct 208 ms 13788 KB Correct
4 Correct 105 ms 14832 KB Correct
5 Correct 114 ms 15304 KB Correct
6 Correct 218 ms 15004 KB Correct
7 Correct 75 ms 15008 KB Correct
8 Correct 88 ms 13468 KB Correct
9 Correct 219 ms 14028 KB Correct
10 Correct 203 ms 14748 KB Correct
11 Correct 163 ms 14060 KB Correct
12 Correct 117 ms 15428 KB Correct
13 Correct 287 ms 13916 KB Correct
14 Correct 88 ms 13296 KB Correct
15 Correct 82 ms 13560 KB Correct
16 Correct 239 ms 14544 KB Correct
17 Correct 211 ms 15796 KB Correct
18 Correct 127 ms 13132 KB Correct
19 Correct 97 ms 13468 KB Correct
20 Correct 159 ms 12964 KB Correct
21 Correct 88 ms 14920 KB Correct
22 Correct 90 ms 13740 KB Correct
23 Correct 225 ms 14260 KB Correct
24 Correct 221 ms 14496 KB Correct
25 Correct 107 ms 13876 KB Correct
26 Correct 92 ms 14492 KB Correct
27 Correct 102 ms 13408 KB Correct
28 Correct 91 ms 13816 KB Correct
29 Correct 100 ms 14296 KB Correct
30 Correct 219 ms 14156 KB Correct
31 Correct 222 ms 13324 KB Correct
32 Correct 101 ms 15416 KB Correct
33 Correct 230 ms 14160 KB Correct
34 Correct 256 ms 14400 KB Correct
35 Correct 76 ms 13396 KB Correct
36 Correct 96 ms 13060 KB Correct
37 Correct 238 ms 14308 KB Correct
38 Correct 234 ms 14492 KB Correct
39 Correct 278 ms 14972 KB Correct
40 Correct 151 ms 15528 KB Correct
41 Correct 200 ms 14628 KB Correct
42 Correct 86 ms 14320 KB Correct
43 Correct 95 ms 14160 KB Correct
44 Correct 237 ms 14576 KB Correct
45 Correct 244 ms 12768 KB Correct
46 Correct 100 ms 13828 KB Correct
47 Correct 91 ms 13824 KB Correct
48 Correct 107 ms 14500 KB Correct
49 Correct 81 ms 12900 KB Correct
50 Correct 88 ms 14856 KB Correct
51 Correct 79 ms 9224 KB Correct
52 Correct 87 ms 9372 KB Correct
53 Correct 82 ms 9220 KB Correct
54 Correct 92 ms 12188 KB Correct
55 Correct 131 ms 11532 KB Correct
56 Correct 173 ms 11776 KB Correct
57 Correct 87 ms 8948 KB Correct
58 Correct 96 ms 8772 KB Correct
59 Correct 79 ms 8864 KB Correct
60 Correct 80 ms 8936 KB Correct
61 Correct 81 ms 8868 KB Correct
62 Correct 74 ms 8940 KB Correct
63 Correct 81 ms 8868 KB Correct
64 Correct 55 ms 7840 KB Correct
65 Correct 61 ms 7848 KB Correct
66 Correct 81 ms 8776 KB Correct
67 Correct 82 ms 8864 KB Correct
68 Correct 79 ms 8940 KB Correct
69 Correct 81 ms 8696 KB Correct
70 Correct 54 ms 7828 KB Correct
71 Correct 60 ms 7832 KB Correct
72 Correct 62 ms 7828 KB Correct
73 Correct 56 ms 7840 KB Correct
74 Correct 54 ms 7824 KB Correct
75 Correct 55 ms 7848 KB Correct
76 Correct 84 ms 9120 KB Correct
77 Correct 83 ms 8924 KB Correct
78 Correct 80 ms 8956 KB Correct
79 Correct 81 ms 8856 KB Correct
80 Correct 88 ms 9048 KB Correct
81 Correct 77 ms 8764 KB Correct
82 Correct 88 ms 9120 KB Correct
83 Correct 82 ms 8944 KB Correct
84 Correct 84 ms 8904 KB Correct
85 Correct 87 ms 8780 KB Correct
86 Correct 87 ms 9120 KB Correct
87 Correct 83 ms 8864 KB Correct
88 Correct 89 ms 8940 KB Correct
89 Correct 77 ms 9124 KB Correct
90 Correct 93 ms 9112 KB Correct
91 Correct 77 ms 8940 KB Correct
92 Correct 93 ms 8848 KB Correct
93 Correct 84 ms 9016 KB Correct
94 Correct 89 ms 9048 KB Correct
95 Correct 84 ms 8928 KB Correct
96 Correct 83 ms 8960 KB Correct
97 Correct 86 ms 9120 KB Correct
98 Correct 89 ms 9048 KB Correct
99 Correct 80 ms 8952 KB Correct
100 Correct 90 ms 9288 KB Correct
101 Correct 77 ms 8932 KB Correct
102 Correct 84 ms 8944 KB Correct
103 Correct 81 ms 8940 KB Correct
104 Correct 84 ms 9212 KB Correct
105 Correct 81 ms 8868 KB Correct
106 Correct 82 ms 9208 KB Correct
107 Correct 83 ms 9192 KB Correct
108 Correct 79 ms 9212 KB Correct
109 Correct 87 ms 9204 KB Correct
110 Correct 88 ms 9380 KB Correct
111 Correct 94 ms 9372 KB Correct
112 Correct 86 ms 9372 KB Correct
113 Correct 82 ms 9120 KB Correct
114 Correct 83 ms 9128 KB Correct
115 Correct 73 ms 9240 KB Correct
116 Correct 98 ms 9200 KB Correct
117 Correct 93 ms 9372 KB Correct
118 Correct 94 ms 9116 KB Correct
119 Correct 91 ms 9052 KB Correct
120 Correct 90 ms 9200 KB Correct
121 Correct 80 ms 8956 KB Correct
122 Correct 96 ms 9220 KB Correct
123 Correct 100 ms 12188 KB Correct
124 Correct 145 ms 11544 KB Correct
125 Correct 171 ms 11780 KB Correct
126 Correct 84 ms 8928 KB Correct
127 Correct 82 ms 8860 KB Correct
128 Correct 84 ms 8956 KB Correct
129 Correct 78 ms 8868 KB Correct
130 Correct 88 ms 8872 KB Correct
131 Correct 83 ms 9100 KB Correct
132 Correct 70 ms 8788 KB Correct
133 Correct 59 ms 7844 KB Correct
134 Correct 63 ms 7724 KB Correct
135 Correct 75 ms 8860 KB Correct
136 Correct 78 ms 8968 KB Correct
137 Correct 82 ms 8960 KB Correct
138 Correct 82 ms 8932 KB Correct
139 Correct 52 ms 7840 KB Correct
140 Correct 60 ms 7632 KB Correct
141 Correct 61 ms 7760 KB Correct
142 Correct 58 ms 7848 KB Correct
143 Correct 60 ms 7848 KB Correct
144 Correct 62 ms 7828 KB Correct
145 Correct 82 ms 8780 KB Correct
146 Correct 81 ms 9124 KB Correct
147 Correct 82 ms 8956 KB Correct
148 Correct 83 ms 8772 KB Correct
149 Correct 87 ms 9124 KB Correct
150 Correct 78 ms 8860 KB Correct
151 Correct 83 ms 9380 KB Correct
152 Correct 89 ms 9036 KB Correct
153 Correct 90 ms 9136 KB Correct
154 Correct 92 ms 8960 KB Correct
155 Correct 86 ms 8960 KB Correct
156 Correct 79 ms 8868 KB Correct
157 Correct 92 ms 8860 KB Correct
158 Correct 82 ms 9196 KB Correct
159 Correct 88 ms 8936 KB Correct
160 Correct 84 ms 8936 KB Correct
161 Correct 86 ms 9112 KB Correct
162 Correct 84 ms 9112 KB Correct
163 Correct 89 ms 9052 KB Correct
164 Correct 88 ms 8708 KB Correct
165 Correct 88 ms 8960 KB Correct
166 Correct 96 ms 9048 KB Correct
167 Correct 88 ms 9216 KB Correct
168 Correct 92 ms 9108 KB Correct
169 Correct 82 ms 9040 KB Correct
170 Correct 91 ms 8932 KB Correct
171 Correct 91 ms 9216 KB Correct
172 Correct 81 ms 8860 KB Correct
173 Correct 90 ms 9376 KB Correct
174 Correct 86 ms 8868 KB Correct
175 Correct 88 ms 9116 KB Correct
176 Correct 82 ms 9116 KB Correct
177 Correct 88 ms 9232 KB Correct
178 Correct 88 ms 9280 KB Correct
179 Correct 87 ms 9308 KB Correct
180 Correct 87 ms 9124 KB Correct
181 Correct 78 ms 9376 KB Correct
182 Correct 86 ms 9200 KB Correct
183 Correct 83 ms 9116 KB Correct
184 Correct 82 ms 9388 KB Correct
185 Correct 213 ms 13392 KB Correct
186 Correct 219 ms 14236 KB Correct
187 Correct 128 ms 14740 KB Correct
188 Correct 120 ms 15556 KB Correct
189 Correct 215 ms 15004 KB Correct
190 Correct 96 ms 15260 KB Correct
191 Correct 95 ms 13560 KB Correct
192 Correct 222 ms 13980 KB Correct
193 Correct 237 ms 14436 KB Correct
194 Correct 176 ms 13980 KB Correct
195 Correct 117 ms 15364 KB Correct
196 Correct 273 ms 13960 KB Correct
197 Correct 89 ms 13468 KB Correct
198 Correct 88 ms 13784 KB Correct
199 Correct 223 ms 14532 KB Correct
200 Correct 225 ms 15800 KB Correct
201 Correct 126 ms 12896 KB Correct
202 Correct 93 ms 13560 KB Correct
203 Correct 146 ms 12816 KB Correct
204 Correct 95 ms 15008 KB Correct
205 Correct 87 ms 13732 KB Correct
206 Correct 209 ms 13984 KB Correct
207 Correct 223 ms 14580 KB Correct
208 Correct 106 ms 13828 KB Correct
209 Correct 99 ms 14332 KB Correct
210 Correct 87 ms 13144 KB Correct
211 Correct 90 ms 13620 KB Correct
212 Correct 100 ms 14344 KB Correct
213 Correct 249 ms 14564 KB Correct
214 Correct 219 ms 13144 KB Correct
215 Correct 100 ms 15008 KB Correct
216 Correct 244 ms 14452 KB Correct
217 Correct 246 ms 14404 KB Correct
218 Correct 75 ms 13212 KB Correct
219 Correct 88 ms 12796 KB Correct
220 Correct 216 ms 14328 KB Correct
221 Correct 220 ms 14288 KB Correct
222 Correct 279 ms 15072 KB Correct
223 Correct 152 ms 15516 KB Correct
224 Correct 205 ms 14776 KB Correct
225 Correct 79 ms 14236 KB Correct
226 Correct 90 ms 14328 KB Correct
227 Correct 207 ms 14592 KB Correct
228 Correct 223 ms 13064 KB Correct
229 Correct 89 ms 13404 KB Correct
230 Correct 94 ms 13728 KB Correct
231 Correct 92 ms 14680 KB Correct
232 Correct 87 ms 12792 KB Correct
233 Correct 82 ms 14832 KB Correct
234 Correct 101 ms 11860 KB Correct
235 Correct 104 ms 11716 KB Correct
236 Correct 63 ms 7840 KB Correct
237 Correct 60 ms 7860 KB Correct
238 Correct 57 ms 7772 KB Correct
239 Correct 47 ms 7208 KB Correct
240 Correct 92 ms 8712 KB Correct
241 Correct 82 ms 8872 KB Correct
242 Correct 84 ms 9132 KB Correct
243 Correct 87 ms 8860 KB Correct
244 Correct 86 ms 9128 KB Correct
245 Correct 93 ms 8864 KB Correct
246 Correct 90 ms 8864 KB Correct
247 Correct 84 ms 8956 KB Correct
248 Correct 84 ms 8860 KB Correct
249 Correct 83 ms 9372 KB Correct
250 Correct 83 ms 8952 KB Correct
251 Correct 89 ms 8860 KB Correct
252 Correct 82 ms 8700 KB Correct
253 Correct 87 ms 9208 KB Correct
254 Correct 84 ms 8860 KB Correct
255 Correct 88 ms 8696 KB Correct
256 Correct 83 ms 9100 KB Correct
257 Correct 82 ms 8692 KB Correct
258 Correct 91 ms 9216 KB Correct
259 Correct 84 ms 8864 KB Correct
260 Correct 86 ms 8860 KB Correct
261 Correct 83 ms 8700 KB Correct
262 Correct 83 ms 9120 KB Correct
263 Correct 83 ms 9040 KB Correct
264 Correct 82 ms 8956 KB Correct
265 Correct 61 ms 7832 KB Correct
266 Correct 56 ms 7848 KB Correct
267 Correct 62 ms 7844 KB Correct
268 Correct 62 ms 7844 KB Correct
269 Correct 60 ms 7832 KB Correct
270 Correct 61 ms 7584 KB Correct
271 Correct 62 ms 7980 KB Correct
272 Correct 60 ms 7836 KB Correct
273 Correct 57 ms 7844 KB Correct
274 Correct 56 ms 7832 KB Correct
275 Correct 63 ms 7716 KB Correct
276 Correct 62 ms 8100 KB Correct
277 Correct 61 ms 7812 KB Correct
278 Correct 60 ms 7844 KB Correct
279 Correct 61 ms 8104 KB Correct
280 Correct 89 ms 9204 KB Correct
281 Correct 79 ms 9464 KB Correct
282 Correct 82 ms 9124 KB Correct
283 Correct 83 ms 9212 KB Correct
284 Correct 83 ms 9208 KB Correct
285 Correct 91 ms 9456 KB Correct
286 Correct 86 ms 9640 KB Correct
287 Correct 87 ms 9292 KB Correct
288 Correct 82 ms 9116 KB Correct
289 Correct 81 ms 9296 KB Correct