Submission #1065087

# Submission time Handle Problem Language Result Execution time Memory
1065087 2024-08-18T22:28:52 Z beaconmc The Ties That Guide Us (CEOI23_incursion) C++17
60 / 100
274 ms 15788 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 root = -1;
    for (auto&i : edges[cent]){
        if (i != par[cent]){
            root = i;
            dfs(root, -1, 0);
            break;
        }
    }
    ll cent2 = centfind(root, -1);


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


    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 217 ms 13388 KB Correct
2 Correct 216 ms 13984 KB Correct
3 Correct 124 ms 14740 KB Correct
4 Correct 109 ms 15368 KB Correct
5 Correct 191 ms 15008 KB Correct
6 Correct 89 ms 15096 KB Correct
7 Correct 86 ms 13476 KB Correct
8 Correct 212 ms 14028 KB Correct
9 Correct 218 ms 14676 KB Correct
10 Correct 156 ms 13692 KB Correct
11 Correct 117 ms 15272 KB Correct
12 Correct 273 ms 13964 KB Correct
13 Correct 92 ms 13476 KB Correct
14 Correct 88 ms 13648 KB Correct
15 Correct 234 ms 14584 KB Correct
16 Correct 217 ms 15788 KB Correct
17 Correct 133 ms 12800 KB Correct
18 Correct 96 ms 13640 KB Correct
19 Correct 153 ms 12880 KB Correct
20 Correct 80 ms 15084 KB Correct
21 Correct 88 ms 13728 KB Correct
22 Correct 215 ms 14068 KB Correct
23 Correct 213 ms 14404 KB Correct
24 Correct 99 ms 14040 KB Correct
25 Correct 102 ms 14320 KB Correct
26 Correct 91 ms 13212 KB Correct
27 Correct 89 ms 13884 KB Correct
28 Correct 92 ms 14384 KB Correct
29 Correct 211 ms 14500 KB Correct
30 Correct 236 ms 13468 KB Correct
31 Correct 93 ms 15264 KB Correct
32 Correct 246 ms 14320 KB Correct
33 Correct 250 ms 14492 KB Correct
34 Correct 88 ms 13220 KB Correct
35 Correct 90 ms 12784 KB Correct
36 Correct 234 ms 14240 KB Correct
37 Correct 231 ms 14444 KB Correct
38 Correct 271 ms 14920 KB Correct
39 Correct 163 ms 15368 KB Correct
40 Correct 183 ms 14940 KB Correct
41 Correct 96 ms 14576 KB Correct
42 Correct 80 ms 14336 KB Correct
43 Correct 245 ms 14336 KB Correct
44 Correct 223 ms 12740 KB Correct
45 Correct 90 ms 13476 KB Correct
46 Correct 82 ms 13988 KB Correct
47 Correct 105 ms 14848 KB Correct
48 Correct 94 ms 12948 KB Correct
49 Correct 84 ms 14748 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 9228 KB Correct
2 Correct 78 ms 8964 KB Correct
3 Correct 83 ms 9064 KB Correct
4 Correct 102 ms 12524 KB Correct
5 Correct 151 ms 11788 KB Correct
6 Correct 174 ms 11644 KB Correct
7 Correct 82 ms 8692 KB Correct
8 Correct 82 ms 9116 KB Correct
9 Correct 79 ms 8680 KB Correct
10 Correct 81 ms 8788 KB Correct
11 Correct 76 ms 8680 KB Correct
12 Correct 79 ms 8692 KB Correct
13 Correct 84 ms 8940 KB Correct
14 Correct 63 ms 7756 KB Correct
15 Correct 55 ms 7856 KB Correct
16 Correct 72 ms 8860 KB Correct
17 Correct 79 ms 8864 KB Correct
18 Correct 76 ms 8948 KB Correct
19 Correct 74 ms 8932 KB Correct
20 Correct 61 ms 7844 KB Correct
21 Correct 56 ms 7580 KB Correct
22 Correct 56 ms 7852 KB Correct
23 Correct 60 ms 7844 KB Correct
24 Correct 65 ms 7848 KB Correct
25 Correct 64 ms 7840 KB Correct
26 Correct 86 ms 8692 KB Correct
27 Correct 74 ms 8860 KB Correct
28 Correct 83 ms 8776 KB Correct
29 Correct 82 ms 8768 KB Correct
30 Correct 94 ms 8956 KB Correct
31 Correct 83 ms 8964 KB Correct
32 Correct 93 ms 8960 KB Correct
33 Correct 90 ms 8952 KB Correct
34 Correct 81 ms 9120 KB Correct
35 Correct 78 ms 8952 KB Correct
36 Correct 81 ms 9124 KB Correct
37 Correct 82 ms 8688 KB Correct
38 Correct 80 ms 9112 KB Correct
39 Correct 80 ms 8944 KB Correct
40 Correct 86 ms 8940 KB Correct
41 Correct 83 ms 8864 KB Correct
42 Correct 80 ms 8856 KB Correct
43 Correct 81 ms 9212 KB Correct
44 Correct 86 ms 9212 KB Correct
45 Correct 74 ms 8772 KB Correct
46 Correct 95 ms 9212 KB Correct
47 Correct 83 ms 8952 KB Correct
48 Correct 89 ms 9200 KB Correct
49 Correct 91 ms 8936 KB Correct
50 Correct 81 ms 9196 KB Correct
51 Correct 95 ms 9124 KB Correct
52 Correct 78 ms 8868 KB Correct
53 Correct 71 ms 8872 KB Correct
54 Correct 80 ms 8956 KB Correct
55 Correct 79 ms 8712 KB Correct
56 Correct 80 ms 9212 KB Correct
57 Correct 79 ms 9204 KB Correct
58 Correct 83 ms 9116 KB Correct
59 Correct 86 ms 9120 KB Correct
60 Correct 76 ms 9280 KB Correct
61 Correct 78 ms 9212 KB Correct
62 Correct 82 ms 9168 KB Correct
63 Correct 87 ms 9204 KB Correct
64 Correct 90 ms 8936 KB Correct
65 Correct 79 ms 9132 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4616 KB Correct
2 Correct 217 ms 13388 KB Correct
3 Correct 216 ms 13984 KB Correct
4 Correct 124 ms 14740 KB Correct
5 Correct 109 ms 15368 KB Correct
6 Correct 191 ms 15008 KB Correct
7 Correct 89 ms 15096 KB Correct
8 Correct 86 ms 13476 KB Correct
9 Correct 212 ms 14028 KB Correct
10 Correct 218 ms 14676 KB Correct
11 Correct 156 ms 13692 KB Correct
12 Correct 117 ms 15272 KB Correct
13 Correct 273 ms 13964 KB Correct
14 Correct 92 ms 13476 KB Correct
15 Correct 88 ms 13648 KB Correct
16 Correct 234 ms 14584 KB Correct
17 Correct 217 ms 15788 KB Correct
18 Correct 133 ms 12800 KB Correct
19 Correct 96 ms 13640 KB Correct
20 Correct 153 ms 12880 KB Correct
21 Correct 80 ms 15084 KB Correct
22 Correct 88 ms 13728 KB Correct
23 Correct 215 ms 14068 KB Correct
24 Correct 213 ms 14404 KB Correct
25 Correct 99 ms 14040 KB Correct
26 Correct 102 ms 14320 KB Correct
27 Correct 91 ms 13212 KB Correct
28 Correct 89 ms 13884 KB Correct
29 Correct 92 ms 14384 KB Correct
30 Correct 211 ms 14500 KB Correct
31 Correct 236 ms 13468 KB Correct
32 Correct 93 ms 15264 KB Correct
33 Correct 246 ms 14320 KB Correct
34 Correct 250 ms 14492 KB Correct
35 Correct 88 ms 13220 KB Correct
36 Correct 90 ms 12784 KB Correct
37 Correct 234 ms 14240 KB Correct
38 Correct 231 ms 14444 KB Correct
39 Correct 271 ms 14920 KB Correct
40 Correct 163 ms 15368 KB Correct
41 Correct 183 ms 14940 KB Correct
42 Correct 96 ms 14576 KB Correct
43 Correct 80 ms 14336 KB Correct
44 Correct 245 ms 14336 KB Correct
45 Correct 223 ms 12740 KB Correct
46 Correct 90 ms 13476 KB Correct
47 Correct 82 ms 13988 KB Correct
48 Correct 105 ms 14848 KB Correct
49 Correct 94 ms 12948 KB Correct
50 Correct 84 ms 14748 KB Correct
51 Correct 81 ms 9228 KB Correct
52 Correct 78 ms 8964 KB Correct
53 Correct 83 ms 9064 KB Correct
54 Correct 102 ms 12524 KB Correct
55 Correct 151 ms 11788 KB Correct
56 Correct 174 ms 11644 KB Correct
57 Correct 82 ms 8692 KB Correct
58 Correct 82 ms 9116 KB Correct
59 Correct 79 ms 8680 KB Correct
60 Correct 81 ms 8788 KB Correct
61 Correct 76 ms 8680 KB Correct
62 Correct 79 ms 8692 KB Correct
63 Correct 84 ms 8940 KB Correct
64 Correct 63 ms 7756 KB Correct
65 Correct 55 ms 7856 KB Correct
66 Correct 72 ms 8860 KB Correct
67 Correct 79 ms 8864 KB Correct
68 Correct 76 ms 8948 KB Correct
69 Correct 74 ms 8932 KB Correct
70 Correct 61 ms 7844 KB Correct
71 Correct 56 ms 7580 KB Correct
72 Correct 56 ms 7852 KB Correct
73 Correct 60 ms 7844 KB Correct
74 Correct 65 ms 7848 KB Correct
75 Correct 64 ms 7840 KB Correct
76 Correct 86 ms 8692 KB Correct
77 Correct 74 ms 8860 KB Correct
78 Correct 83 ms 8776 KB Correct
79 Correct 82 ms 8768 KB Correct
80 Correct 94 ms 8956 KB Correct
81 Correct 83 ms 8964 KB Correct
82 Correct 93 ms 8960 KB Correct
83 Correct 90 ms 8952 KB Correct
84 Correct 81 ms 9120 KB Correct
85 Correct 78 ms 8952 KB Correct
86 Correct 81 ms 9124 KB Correct
87 Correct 82 ms 8688 KB Correct
88 Correct 80 ms 9112 KB Correct
89 Correct 80 ms 8944 KB Correct
90 Correct 86 ms 8940 KB Correct
91 Correct 83 ms 8864 KB Correct
92 Correct 80 ms 8856 KB Correct
93 Correct 81 ms 9212 KB Correct
94 Correct 86 ms 9212 KB Correct
95 Correct 74 ms 8772 KB Correct
96 Correct 95 ms 9212 KB Correct
97 Correct 83 ms 8952 KB Correct
98 Correct 89 ms 9200 KB Correct
99 Correct 91 ms 8936 KB Correct
100 Correct 81 ms 9196 KB Correct
101 Correct 95 ms 9124 KB Correct
102 Correct 78 ms 8868 KB Correct
103 Correct 71 ms 8872 KB Correct
104 Correct 80 ms 8956 KB Correct
105 Correct 79 ms 8712 KB Correct
106 Correct 80 ms 9212 KB Correct
107 Correct 79 ms 9204 KB Correct
108 Correct 83 ms 9116 KB Correct
109 Correct 86 ms 9120 KB Correct
110 Correct 76 ms 9280 KB Correct
111 Correct 78 ms 9212 KB Correct
112 Correct 82 ms 9168 KB Correct
113 Correct 87 ms 9204 KB Correct
114 Correct 90 ms 8936 KB Correct
115 Correct 79 ms 9132 KB Correct
116 Correct 84 ms 9252 KB Correct
117 Correct 89 ms 8956 KB Correct
118 Correct 82 ms 9216 KB Correct
119 Correct 87 ms 9120 KB Correct
120 Correct 76 ms 9048 KB Correct
121 Correct 84 ms 9136 KB Correct
122 Correct 80 ms 8940 KB Correct
123 Correct 89 ms 12188 KB Correct
124 Correct 132 ms 11752 KB Correct
125 Correct 151 ms 11636 KB Correct
126 Correct 82 ms 8692 KB Correct
127 Correct 83 ms 8860 KB Correct
128 Correct 72 ms 8704 KB Correct
129 Correct 79 ms 8860 KB Correct
130 Correct 84 ms 8856 KB Correct
131 Correct 69 ms 8936 KB Correct
132 Correct 84 ms 8952 KB Correct
133 Correct 54 ms 7844 KB Correct
134 Correct 50 ms 7836 KB Correct
135 Correct 77 ms 8864 KB Correct
136 Correct 86 ms 8708 KB Correct
137 Correct 78 ms 8864 KB Correct
138 Correct 80 ms 8860 KB Correct
139 Correct 64 ms 8088 KB Correct
140 Correct 62 ms 7840 KB Correct
141 Correct 64 ms 8088 KB Correct
142 Correct 63 ms 7836 KB Correct
143 Correct 54 ms 7832 KB Correct
144 Correct 57 ms 7836 KB Correct
145 Correct 73 ms 9220 KB Correct
146 Correct 79 ms 8788 KB Correct
147 Correct 74 ms 8864 KB Correct
148 Correct 80 ms 9204 KB Correct
149 Correct 77 ms 9200 KB Correct
150 Correct 84 ms 8936 KB Correct
151 Correct 81 ms 9116 KB Correct
152 Correct 84 ms 9056 KB Correct
153 Correct 74 ms 8956 KB Correct
154 Correct 80 ms 8700 KB Correct
155 Correct 79 ms 9128 KB Correct
156 Correct 79 ms 8936 KB Correct
157 Correct 77 ms 8860 KB Correct
158 Correct 79 ms 9116 KB Correct
159 Correct 78 ms 9124 KB Correct
160 Correct 83 ms 8956 KB Correct
161 Correct 82 ms 8860 KB Correct
162 Correct 77 ms 9216 KB Correct
163 Correct 83 ms 9132 KB Correct
164 Correct 83 ms 8860 KB Correct
165 Correct 77 ms 9116 KB Correct
166 Correct 87 ms 9060 KB Correct
167 Correct 89 ms 8968 KB Correct
168 Correct 89 ms 8944 KB Correct
169 Correct 83 ms 8864 KB Correct
170 Correct 83 ms 9112 KB Correct
171 Correct 87 ms 9200 KB Correct
172 Correct 81 ms 9100 KB Correct
173 Correct 82 ms 9200 KB Correct
174 Correct 82 ms 8792 KB Correct
175 Correct 79 ms 9124 KB Correct
176 Correct 87 ms 9284 KB Correct
177 Correct 89 ms 9216 KB Correct
178 Correct 80 ms 9464 KB Correct
179 Correct 78 ms 9372 KB Correct
180 Correct 80 ms 9116 KB Correct
181 Correct 70 ms 9216 KB Correct
182 Correct 83 ms 9212 KB Correct
183 Correct 79 ms 9376 KB Correct
184 Correct 86 ms 9296 KB Correct
185 Correct 212 ms 13548 KB Correct
186 Correct 235 ms 13980 KB Correct
187 Correct 131 ms 14840 KB Correct
188 Correct 111 ms 15272 KB Correct
189 Correct 231 ms 15008 KB Correct
190 Correct 88 ms 15064 KB Correct
191 Correct 87 ms 13556 KB Correct
192 Correct 212 ms 13932 KB Correct
193 Correct 217 ms 14772 KB Correct
194 Correct 164 ms 13980 KB Correct
195 Correct 104 ms 15448 KB Correct
196 Correct 274 ms 13984 KB Correct
197 Correct 82 ms 13472 KB Correct
198 Correct 83 ms 13572 KB Correct
199 Correct 195 ms 14620 KB Correct
200 Correct 205 ms 15692 KB Correct
201 Correct 122 ms 12792 KB Correct
202 Correct 96 ms 13468 KB Correct
203 Correct 144 ms 12884 KB Correct
204 Correct 96 ms 14828 KB Correct
205 Correct 89 ms 13820 KB Correct
206 Correct 204 ms 14060 KB Correct
207 Correct 211 ms 14148 KB Correct
208 Correct 115 ms 13644 KB Correct
209 Correct 99 ms 14236 KB Correct
210 Correct 99 ms 13456 KB Correct
211 Correct 94 ms 13816 KB Correct
212 Correct 84 ms 14340 KB Correct
213 Correct 201 ms 14164 KB Correct
214 Correct 220 ms 13232 KB Correct
215 Correct 98 ms 15012 KB Correct
216 Correct 228 ms 14240 KB Correct
217 Correct 249 ms 14500 KB Correct
218 Correct 86 ms 13308 KB Correct
219 Correct 87 ms 12800 KB Correct
220 Correct 209 ms 14268 KB Correct
221 Correct 211 ms 14492 KB Correct
222 Correct 259 ms 15060 KB Correct
223 Correct 156 ms 15156 KB Correct
224 Correct 165 ms 14688 KB Correct
225 Correct 87 ms 14336 KB Correct
226 Correct 87 ms 14232 KB Correct
227 Correct 216 ms 14336 KB Correct
228 Correct 197 ms 13060 KB Correct
229 Correct 86 ms 13308 KB Correct
230 Correct 84 ms 13980 KB Correct
231 Correct 99 ms 14416 KB Correct
232 Correct 84 ms 12792 KB Correct
233 Correct 89 ms 14844 KB Correct
234 Correct 99 ms 11908 KB Correct
235 Correct 100 ms 11616 KB Correct
236 Correct 54 ms 7852 KB Correct
237 Correct 56 ms 7764 KB Correct
238 Correct 61 ms 7852 KB Correct
239 Correct 46 ms 6880 KB Correct
240 Correct 80 ms 8864 KB Correct
241 Correct 80 ms 8864 KB Correct
242 Correct 83 ms 9116 KB Correct
243 Correct 91 ms 9104 KB Correct
244 Correct 88 ms 8864 KB Correct
245 Correct 83 ms 8860 KB Correct
246 Correct 74 ms 8928 KB Correct
247 Correct 76 ms 9120 KB Correct
248 Correct 74 ms 8808 KB Correct
249 Correct 78 ms 8948 KB Correct
250 Correct 80 ms 8864 KB Correct
251 Correct 76 ms 9000 KB Correct
252 Correct 84 ms 8864 KB Correct
253 Correct 81 ms 8868 KB Correct
254 Correct 80 ms 9044 KB Correct
255 Correct 76 ms 8704 KB Correct
256 Correct 80 ms 8860 KB Correct
257 Correct 78 ms 8960 KB Correct
258 Correct 73 ms 8944 KB Correct
259 Correct 74 ms 8864 KB Correct
260 Correct 77 ms 9120 KB Correct
261 Correct 74 ms 8696 KB Correct
262 Correct 80 ms 8872 KB Correct
263 Correct 84 ms 8956 KB Correct
264 Correct 80 ms 8952 KB Correct
265 Correct 60 ms 7956 KB Correct
266 Correct 56 ms 7856 KB Correct
267 Incorrect 55 ms 7836 KB Not correct
268 Halted 0 ms 0 KB -