답안 #1065020

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1065020 2024-08-18T21:23:19 Z beaconmc The Ties That Guide Us (CEOI23_incursion) C++17
60 / 100
284 ms 15620 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){
    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;

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

    ll cent = centfind(4, -1);

    dfs(cent, -1, 0);


    while (safe != -1){
        ties[safe-1] = 1;
        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;

    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);

    dfs(cent, -1, 0);
    visited[curr] = 1;

    //cout << cent << endl;

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

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

        }
        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){
            if (curr != cent && visited[par[curr]] == 0){
                bool nextto = false;
                for (auto&i : edges[curr]){
                    if (i==cent) nextto = true;
                }
                if (!nextto) return;
                t = visit(par[curr]);
                visited[par[curr]] = 1;
                curr = par[curr];
            }else{
                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);
      |                  ~~~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4356 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 211 ms 12856 KB Correct
2 Correct 224 ms 13604 KB Correct
3 Correct 105 ms 14548 KB Correct
4 Correct 105 ms 15520 KB Correct
5 Correct 191 ms 15364 KB Correct
6 Correct 83 ms 14316 KB Correct
7 Correct 86 ms 14492 KB Correct
8 Correct 215 ms 12976 KB Correct
9 Correct 224 ms 15088 KB Correct
10 Correct 160 ms 15080 KB Correct
11 Correct 100 ms 14748 KB Correct
12 Correct 284 ms 13432 KB Correct
13 Correct 89 ms 13828 KB Correct
14 Correct 84 ms 13636 KB Correct
15 Correct 219 ms 14584 KB Correct
16 Correct 201 ms 14492 KB Correct
17 Correct 125 ms 13732 KB Correct
18 Correct 89 ms 12624 KB Correct
19 Correct 143 ms 13316 KB Correct
20 Correct 91 ms 14920 KB Correct
21 Correct 88 ms 13468 KB Correct
22 Correct 200 ms 14048 KB Correct
23 Correct 208 ms 14996 KB Correct
24 Correct 99 ms 13036 KB Correct
25 Correct 86 ms 13324 KB Correct
26 Correct 99 ms 12600 KB Correct
27 Correct 84 ms 14584 KB Correct
28 Correct 83 ms 13848 KB Correct
29 Correct 199 ms 14320 KB Correct
30 Correct 221 ms 14240 KB Correct
31 Correct 89 ms 15620 KB Correct
32 Correct 247 ms 13252 KB Correct
33 Correct 249 ms 13720 KB Correct
34 Correct 89 ms 13312 KB Correct
35 Correct 77 ms 13824 KB Correct
36 Correct 233 ms 15092 KB Correct
37 Correct 221 ms 15260 KB Correct
38 Correct 262 ms 13980 KB Correct
39 Correct 150 ms 14220 KB Correct
40 Correct 187 ms 14592 KB Correct
41 Correct 83 ms 12956 KB Correct
42 Correct 84 ms 14748 KB Correct
43 Correct 203 ms 13548 KB Correct
44 Correct 200 ms 13212 KB Correct
45 Correct 84 ms 12956 KB Correct
46 Correct 88 ms 14392 KB Correct
47 Correct 103 ms 14576 KB Correct
48 Correct 84 ms 12444 KB Correct
49 Correct 91 ms 14328 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 8716 KB Correct
2 Correct 91 ms 9052 KB Correct
3 Correct 83 ms 8864 KB Correct
4 Correct 93 ms 11404 KB Correct
5 Correct 132 ms 11340 KB Correct
6 Correct 147 ms 11268 KB Correct
7 Correct 71 ms 8672 KB Correct
8 Correct 86 ms 8680 KB Correct
9 Correct 98 ms 8768 KB Correct
10 Correct 76 ms 8408 KB Correct
11 Correct 82 ms 8692 KB Correct
12 Correct 69 ms 8720 KB Correct
13 Correct 74 ms 8344 KB Correct
14 Correct 61 ms 7328 KB Correct
15 Correct 59 ms 7272 KB Correct
16 Correct 75 ms 8692 KB Correct
17 Correct 77 ms 8440 KB Correct
18 Correct 72 ms 8436 KB Correct
19 Correct 79 ms 8700 KB Correct
20 Correct 60 ms 7320 KB Correct
21 Correct 59 ms 7320 KB Correct
22 Correct 47 ms 7332 KB Correct
23 Correct 60 ms 7340 KB Correct
24 Correct 56 ms 7340 KB Correct
25 Correct 55 ms 7324 KB Correct
26 Correct 84 ms 8856 KB Correct
27 Correct 81 ms 8696 KB Correct
28 Correct 73 ms 8424 KB Correct
29 Correct 78 ms 8692 KB Correct
30 Correct 81 ms 8796 KB Correct
31 Correct 83 ms 8840 KB Correct
32 Correct 81 ms 8948 KB Correct
33 Correct 86 ms 8844 KB Correct
34 Correct 88 ms 8716 KB Correct
35 Correct 80 ms 8692 KB Correct
36 Correct 79 ms 8856 KB Correct
37 Correct 80 ms 8712 KB Correct
38 Correct 78 ms 8604 KB Correct
39 Correct 82 ms 8528 KB Correct
40 Correct 74 ms 8528 KB Correct
41 Correct 70 ms 8548 KB Correct
42 Correct 79 ms 8684 KB Correct
43 Correct 82 ms 8696 KB Correct
44 Correct 72 ms 8912 KB Correct
45 Correct 83 ms 8680 KB Correct
46 Correct 88 ms 8864 KB Correct
47 Correct 81 ms 8956 KB Correct
48 Correct 86 ms 8868 KB Correct
49 Correct 81 ms 8592 KB Correct
50 Correct 82 ms 8700 KB Correct
51 Correct 77 ms 8524 KB Correct
52 Correct 77 ms 8860 KB Correct
53 Correct 77 ms 8544 KB Correct
54 Correct 77 ms 8948 KB Correct
55 Correct 75 ms 8696 KB Correct
56 Correct 83 ms 8708 KB Correct
57 Correct 76 ms 8864 KB Correct
58 Correct 78 ms 9212 KB Correct
59 Correct 86 ms 8864 KB Correct
60 Correct 78 ms 8700 KB Correct
61 Correct 79 ms 8964 KB Correct
62 Correct 79 ms 8700 KB Correct
63 Correct 77 ms 9116 KB Correct
64 Correct 77 ms 8680 KB Correct
65 Correct 78 ms 8944 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4356 KB Correct
2 Correct 211 ms 12856 KB Correct
3 Correct 224 ms 13604 KB Correct
4 Correct 105 ms 14548 KB Correct
5 Correct 105 ms 15520 KB Correct
6 Correct 191 ms 15364 KB Correct
7 Correct 83 ms 14316 KB Correct
8 Correct 86 ms 14492 KB Correct
9 Correct 215 ms 12976 KB Correct
10 Correct 224 ms 15088 KB Correct
11 Correct 160 ms 15080 KB Correct
12 Correct 100 ms 14748 KB Correct
13 Correct 284 ms 13432 KB Correct
14 Correct 89 ms 13828 KB Correct
15 Correct 84 ms 13636 KB Correct
16 Correct 219 ms 14584 KB Correct
17 Correct 201 ms 14492 KB Correct
18 Correct 125 ms 13732 KB Correct
19 Correct 89 ms 12624 KB Correct
20 Correct 143 ms 13316 KB Correct
21 Correct 91 ms 14920 KB Correct
22 Correct 88 ms 13468 KB Correct
23 Correct 200 ms 14048 KB Correct
24 Correct 208 ms 14996 KB Correct
25 Correct 99 ms 13036 KB Correct
26 Correct 86 ms 13324 KB Correct
27 Correct 99 ms 12600 KB Correct
28 Correct 84 ms 14584 KB Correct
29 Correct 83 ms 13848 KB Correct
30 Correct 199 ms 14320 KB Correct
31 Correct 221 ms 14240 KB Correct
32 Correct 89 ms 15620 KB Correct
33 Correct 247 ms 13252 KB Correct
34 Correct 249 ms 13720 KB Correct
35 Correct 89 ms 13312 KB Correct
36 Correct 77 ms 13824 KB Correct
37 Correct 233 ms 15092 KB Correct
38 Correct 221 ms 15260 KB Correct
39 Correct 262 ms 13980 KB Correct
40 Correct 150 ms 14220 KB Correct
41 Correct 187 ms 14592 KB Correct
42 Correct 83 ms 12956 KB Correct
43 Correct 84 ms 14748 KB Correct
44 Correct 203 ms 13548 KB Correct
45 Correct 200 ms 13212 KB Correct
46 Correct 84 ms 12956 KB Correct
47 Correct 88 ms 14392 KB Correct
48 Correct 103 ms 14576 KB Correct
49 Correct 84 ms 12444 KB Correct
50 Correct 91 ms 14328 KB Correct
51 Correct 82 ms 8716 KB Correct
52 Correct 91 ms 9052 KB Correct
53 Correct 83 ms 8864 KB Correct
54 Correct 93 ms 11404 KB Correct
55 Correct 132 ms 11340 KB Correct
56 Correct 147 ms 11268 KB Correct
57 Correct 71 ms 8672 KB Correct
58 Correct 86 ms 8680 KB Correct
59 Correct 98 ms 8768 KB Correct
60 Correct 76 ms 8408 KB Correct
61 Correct 82 ms 8692 KB Correct
62 Correct 69 ms 8720 KB Correct
63 Correct 74 ms 8344 KB Correct
64 Correct 61 ms 7328 KB Correct
65 Correct 59 ms 7272 KB Correct
66 Correct 75 ms 8692 KB Correct
67 Correct 77 ms 8440 KB Correct
68 Correct 72 ms 8436 KB Correct
69 Correct 79 ms 8700 KB Correct
70 Correct 60 ms 7320 KB Correct
71 Correct 59 ms 7320 KB Correct
72 Correct 47 ms 7332 KB Correct
73 Correct 60 ms 7340 KB Correct
74 Correct 56 ms 7340 KB Correct
75 Correct 55 ms 7324 KB Correct
76 Correct 84 ms 8856 KB Correct
77 Correct 81 ms 8696 KB Correct
78 Correct 73 ms 8424 KB Correct
79 Correct 78 ms 8692 KB Correct
80 Correct 81 ms 8796 KB Correct
81 Correct 83 ms 8840 KB Correct
82 Correct 81 ms 8948 KB Correct
83 Correct 86 ms 8844 KB Correct
84 Correct 88 ms 8716 KB Correct
85 Correct 80 ms 8692 KB Correct
86 Correct 79 ms 8856 KB Correct
87 Correct 80 ms 8712 KB Correct
88 Correct 78 ms 8604 KB Correct
89 Correct 82 ms 8528 KB Correct
90 Correct 74 ms 8528 KB Correct
91 Correct 70 ms 8548 KB Correct
92 Correct 79 ms 8684 KB Correct
93 Correct 82 ms 8696 KB Correct
94 Correct 72 ms 8912 KB Correct
95 Correct 83 ms 8680 KB Correct
96 Correct 88 ms 8864 KB Correct
97 Correct 81 ms 8956 KB Correct
98 Correct 86 ms 8868 KB Correct
99 Correct 81 ms 8592 KB Correct
100 Correct 82 ms 8700 KB Correct
101 Correct 77 ms 8524 KB Correct
102 Correct 77 ms 8860 KB Correct
103 Correct 77 ms 8544 KB Correct
104 Correct 77 ms 8948 KB Correct
105 Correct 75 ms 8696 KB Correct
106 Correct 83 ms 8708 KB Correct
107 Correct 76 ms 8864 KB Correct
108 Correct 78 ms 9212 KB Correct
109 Correct 86 ms 8864 KB Correct
110 Correct 78 ms 8700 KB Correct
111 Correct 79 ms 8964 KB Correct
112 Correct 79 ms 8700 KB Correct
113 Correct 77 ms 9116 KB Correct
114 Correct 77 ms 8680 KB Correct
115 Correct 78 ms 8944 KB Correct
116 Correct 74 ms 8948 KB Correct
117 Correct 86 ms 9120 KB Correct
118 Correct 77 ms 9040 KB Correct
119 Correct 81 ms 8940 KB Correct
120 Correct 87 ms 8600 KB Correct
121 Correct 69 ms 9116 KB Correct
122 Correct 75 ms 9116 KB Correct
123 Correct 89 ms 11504 KB Correct
124 Correct 134 ms 11268 KB Correct
125 Correct 174 ms 11256 KB Correct
126 Correct 79 ms 8676 KB Correct
127 Correct 77 ms 8696 KB Correct
128 Correct 80 ms 8508 KB Correct
129 Correct 74 ms 8520 KB Correct
130 Correct 78 ms 8348 KB Correct
131 Correct 76 ms 8444 KB Correct
132 Correct 81 ms 8516 KB Correct
133 Correct 54 ms 7332 KB Correct
134 Correct 51 ms 7316 KB Correct
135 Correct 77 ms 8424 KB Correct
136 Correct 82 ms 8516 KB Correct
137 Correct 68 ms 8440 KB Correct
138 Correct 74 ms 8524 KB Correct
139 Correct 62 ms 7420 KB Correct
140 Correct 62 ms 7328 KB Correct
141 Correct 56 ms 7320 KB Correct
142 Correct 55 ms 7336 KB Correct
143 Correct 59 ms 7320 KB Correct
144 Correct 54 ms 7332 KB Correct
145 Correct 83 ms 8532 KB Correct
146 Correct 78 ms 8860 KB Correct
147 Correct 76 ms 8756 KB Correct
148 Correct 75 ms 8684 KB Correct
149 Correct 82 ms 9060 KB Correct
150 Correct 82 ms 8520 KB Correct
151 Correct 81 ms 8952 KB Correct
152 Correct 80 ms 8604 KB Correct
153 Correct 75 ms 8864 KB Correct
154 Correct 73 ms 8532 KB Correct
155 Correct 72 ms 8708 KB Correct
156 Correct 82 ms 8860 KB Correct
157 Correct 74 ms 8436 KB Correct
158 Correct 75 ms 8604 KB Correct
159 Correct 76 ms 8860 KB Correct
160 Correct 77 ms 9116 KB Correct
161 Correct 76 ms 8796 KB Correct
162 Correct 83 ms 8680 KB Correct
163 Correct 80 ms 8704 KB Correct
164 Correct 71 ms 8660 KB Correct
165 Correct 86 ms 8800 KB Correct
166 Correct 82 ms 8960 KB Correct
167 Correct 72 ms 8540 KB Correct
168 Correct 76 ms 8536 KB Correct
169 Correct 93 ms 8584 KB Correct
170 Correct 79 ms 8912 KB Correct
171 Correct 77 ms 8860 KB Correct
172 Correct 76 ms 8424 KB Correct
173 Correct 73 ms 8628 KB Correct
174 Correct 84 ms 8864 KB Correct
175 Correct 76 ms 8936 KB Correct
176 Correct 81 ms 8936 KB Correct
177 Correct 80 ms 9124 KB Correct
178 Correct 83 ms 8960 KB Correct
179 Correct 77 ms 8948 KB Correct
180 Correct 79 ms 8684 KB Correct
181 Correct 76 ms 8940 KB Correct
182 Correct 78 ms 8872 KB Correct
183 Correct 68 ms 8948 KB Correct
184 Correct 78 ms 9116 KB Correct
185 Correct 227 ms 12764 KB Correct
186 Correct 239 ms 13828 KB Correct
187 Correct 110 ms 14296 KB Correct
188 Correct 96 ms 15356 KB Correct
189 Correct 192 ms 15496 KB Correct
190 Correct 84 ms 13980 KB Correct
191 Correct 83 ms 14496 KB Correct
192 Correct 230 ms 13544 KB Correct
193 Correct 219 ms 14916 KB Correct
194 Correct 159 ms 15004 KB Correct
195 Correct 94 ms 15112 KB Correct
196 Correct 267 ms 13632 KB Correct
197 Correct 87 ms 13572 KB Correct
198 Correct 83 ms 13804 KB Correct
199 Correct 206 ms 14836 KB Correct
200 Correct 216 ms 14496 KB Correct
201 Correct 125 ms 13636 KB Correct
202 Correct 92 ms 12696 KB Correct
203 Correct 183 ms 13304 KB Correct
204 Correct 91 ms 14748 KB Correct
205 Correct 72 ms 13568 KB Correct
206 Correct 210 ms 13884 KB Correct
207 Correct 214 ms 15000 KB Correct
208 Correct 108 ms 12908 KB Correct
209 Correct 92 ms 13084 KB Correct
210 Correct 86 ms 12524 KB Correct
211 Correct 78 ms 14592 KB Correct
212 Correct 92 ms 13824 KB Correct
213 Correct 236 ms 14568 KB Correct
214 Correct 214 ms 14236 KB Correct
215 Correct 101 ms 15496 KB Correct
216 Correct 228 ms 13308 KB Correct
217 Correct 238 ms 13888 KB Correct
218 Correct 84 ms 13500 KB Correct
219 Correct 90 ms 13980 KB Correct
220 Correct 226 ms 15024 KB Correct
221 Correct 216 ms 15120 KB Correct
222 Correct 267 ms 13920 KB Correct
223 Correct 151 ms 13952 KB Correct
224 Correct 190 ms 14504 KB Correct
225 Correct 81 ms 13052 KB Correct
226 Correct 95 ms 14572 KB Correct
227 Correct 224 ms 13544 KB Correct
228 Correct 203 ms 13240 KB Correct
229 Correct 88 ms 13208 KB Correct
230 Correct 88 ms 14096 KB Correct
231 Correct 104 ms 14504 KB Correct
232 Correct 83 ms 12560 KB Correct
233 Correct 90 ms 14572 KB Correct
234 Correct 94 ms 11000 KB Correct
235 Correct 100 ms 10840 KB Correct
236 Correct 57 ms 7280 KB Correct
237 Correct 60 ms 7320 KB Correct
238 Correct 57 ms 7312 KB Correct
239 Correct 47 ms 6752 KB Correct
240 Correct 73 ms 8704 KB Correct
241 Correct 61 ms 8636 KB Correct
242 Correct 81 ms 8708 KB Correct
243 Correct 74 ms 8860 KB Correct
244 Correct 74 ms 8520 KB Correct
245 Correct 80 ms 8428 KB Correct
246 Correct 79 ms 8432 KB Correct
247 Correct 79 ms 8712 KB Correct
248 Correct 84 ms 8536 KB Correct
249 Correct 84 ms 8864 KB Correct
250 Correct 75 ms 8608 KB Correct
251 Correct 74 ms 8440 KB Correct
252 Correct 78 ms 8612 KB Correct
253 Correct 69 ms 8684 KB Correct
254 Correct 79 ms 8860 KB Correct
255 Correct 78 ms 8604 KB Correct
256 Correct 74 ms 8740 KB Correct
257 Correct 78 ms 8716 KB Correct
258 Correct 75 ms 8860 KB Correct
259 Correct 72 ms 8696 KB Correct
260 Correct 78 ms 8528 KB Correct
261 Correct 77 ms 8608 KB Correct
262 Correct 81 ms 8860 KB Correct
263 Correct 86 ms 8868 KB Correct
264 Correct 73 ms 8788 KB Correct
265 Correct 60 ms 7340 KB Correct
266 Correct 59 ms 7320 KB Correct
267 Correct 55 ms 7332 KB Correct
268 Correct 71 ms 7328 KB Correct
269 Correct 59 ms 7328 KB Correct
270 Correct 57 ms 7320 KB Correct
271 Correct 56 ms 7312 KB Correct
272 Incorrect 55 ms 7332 KB Not correct
273 Halted 0 ms 0 KB -