답안 #1081397

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1081397 2024-08-30T03:47:47 Z Evirir The Ties That Guide Us (CEOI23_incursion) C++17
100 / 100
281 ms 13472 KB
#include "incursion.h"
#include <bits/stdc++.h>
using namespace std;

#define setp(x) cout<<fixed<<setprecision(x)
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

int n;
vector<vector<int>> adj;
vector<int> sub, prt;
ii root = {-1, -1};

void init()
{
    adj.resize(n); prt.resize(n); sub.resize(n);
    forn(i,0,n) adj[i].clear();
}

int Visit(int u){ return visit(u + 1); }

void getSub(int u, int p)
{
    sub[u] = 1;
    for (const auto v : adj[u])
    {
        if (v == p) continue;
        getSub(v, u);
        sub[u] += sub[v];
    }
}

bool iscentroid(int u)
{
    if (2 * (n - sub[u]) > n) return false;
    for (const auto& v : adj[u])
    {
        if (v == prt[u]) continue;
        if (2 * sub[v] > n) return false;
    }
    return true;
}

bool isRoot(int u)
{
    // assert(u != -1);
    return root.F == u || root.S == u;
}

void getPrt(int u, int p)
{
    prt[u] = p;
    for (const auto v : adj[u])
    {
        if (v == p) continue;
        getPrt(v, u);
    }
}

void getRoot()
{
    getSub(0, -1);
    getPrt(0, -1);
    int u = 0;
    while (!iscentroid(u))
    {
        for (const auto v : adj[u])
        {
            if (v == prt[u]) continue;
            if (2 * sub[v] > n)
            {
                u = v;
                break;
            }
        }
    }
    root.F = u;
    for (const auto v : adj[u])
    {
        if (iscentroid(v)) root.S = v;
    }
}

vector<int> mark(vector<pair<int, int>> edges, int safe)
{
    n = sz(edges) + 1;
    init();
    safe--;
    for (auto& [u, v] : edges) { u--; v--; }
    for (auto [u, v] : edges)
    {
        adj[u].pb(v);
        adj[v].pb(u);
    }
    getRoot();
    getPrt(root.F, -1);

    int u = safe;
    vector<int> res(n, 0);
    while (!isRoot(u))
    {
        res[u] = 1;
        u = prt[u];
    }
    res[u] = 1;
    return res;
}

void locate(vector<pair<int, int>> edges, int src, int tcnt)
{
    n = sz(edges) + 1;
    init();
    src--;
    for (auto& [u, v] : edges) { u--; v--; }
    for (auto [u, v] : edges)
    {
        adj[u].pb(v);
        adj[v].pb(u);
    }
    getRoot();
    getPrt(root.F, -1);
    getSub(root.F, -1);

    bool vst[n]{};
    int u = src;
    vst[u] = 1;
    while (!isRoot(u) && tcnt == 0)
    {
        u = prt[u];
        tcnt = Visit(u);
        vst[u] = 1;
    }
    if (tcnt == 0)  // go to other root
    {
        u = (u == root.F ? root.S : root.F);
        tcnt = Visit(u);
        vst[u] = 1;
        // assert(tcnt > 0);
    }

    while (true)
    {
        vector<int> nxt;
        for (const auto v : adj[u])
        {
            if (vst[v] || v == prt[u]) continue;
            nxt.pb(v);
        }
        sort(all(nxt), [](int v1, int v2){ return sub[v1] > sub[v2]; });
        // assert(sz(nxt) <= 2);
        bool found = 0;
        for (const auto v : nxt)
        {
            tcnt = Visit(v);
            if (tcnt == 1)
            {
                found = 1;
                u = v;
                break;
            }
            tcnt = Visit(u);
        }
        if (!found) 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 0 ms 776 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 210 ms 11500 KB Correct
2 Correct 216 ms 11656 KB Correct
3 Correct 125 ms 12308 KB Correct
4 Correct 114 ms 12996 KB Correct
5 Correct 216 ms 12724 KB Correct
6 Correct 88 ms 12972 KB Correct
7 Correct 84 ms 11404 KB Correct
8 Correct 212 ms 12128 KB Correct
9 Correct 232 ms 12348 KB Correct
10 Correct 170 ms 11896 KB Correct
11 Correct 107 ms 13212 KB Correct
12 Correct 273 ms 12052 KB Correct
13 Correct 92 ms 11352 KB Correct
14 Correct 88 ms 11612 KB Correct
15 Correct 230 ms 12336 KB Correct
16 Correct 240 ms 13212 KB Correct
17 Correct 121 ms 11348 KB Correct
18 Correct 105 ms 11628 KB Correct
19 Correct 160 ms 11120 KB Correct
20 Correct 94 ms 12536 KB Correct
21 Correct 88 ms 11868 KB Correct
22 Correct 211 ms 12124 KB Correct
23 Correct 202 ms 11920 KB Correct
24 Correct 92 ms 11428 KB Correct
25 Correct 98 ms 12376 KB Correct
26 Correct 95 ms 11116 KB Correct
27 Correct 92 ms 11612 KB Correct
28 Correct 83 ms 12112 KB Correct
29 Correct 209 ms 12092 KB Correct
30 Correct 250 ms 11352 KB Correct
31 Correct 98 ms 12640 KB Correct
32 Correct 239 ms 11968 KB Correct
33 Correct 237 ms 12548 KB Correct
34 Correct 90 ms 11424 KB Correct
35 Correct 89 ms 11164 KB Correct
36 Correct 223 ms 12132 KB Correct
37 Correct 249 ms 12040 KB Correct
38 Correct 279 ms 12664 KB Correct
39 Correct 148 ms 12968 KB Correct
40 Correct 222 ms 12636 KB Correct
41 Correct 92 ms 12380 KB Correct
42 Correct 88 ms 12128 KB Correct
43 Correct 238 ms 11832 KB Correct
44 Correct 207 ms 11168 KB Correct
45 Correct 105 ms 11764 KB Correct
46 Correct 101 ms 11680 KB Correct
47 Correct 99 ms 12272 KB Correct
48 Correct 89 ms 10916 KB Correct
49 Correct 88 ms 12368 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 7844 KB Correct
2 Correct 83 ms 7840 KB Correct
3 Correct 83 ms 8144 KB Correct
4 Correct 99 ms 10328 KB Correct
5 Correct 143 ms 10004 KB Correct
6 Correct 186 ms 10224 KB Correct
7 Correct 78 ms 7584 KB Correct
8 Correct 79 ms 7508 KB Correct
9 Correct 80 ms 7492 KB Correct
10 Correct 76 ms 7516 KB Correct
11 Correct 82 ms 7776 KB Correct
12 Correct 84 ms 7836 KB Correct
13 Correct 80 ms 7584 KB Correct
14 Correct 62 ms 5880 KB Correct
15 Correct 57 ms 5968 KB Correct
16 Correct 76 ms 7500 KB Correct
17 Correct 77 ms 7688 KB Correct
18 Correct 84 ms 7560 KB Correct
19 Correct 88 ms 7752 KB Correct
20 Correct 54 ms 5924 KB Correct
21 Correct 63 ms 5876 KB Correct
22 Correct 55 ms 5900 KB Correct
23 Correct 71 ms 5960 KB Correct
24 Correct 62 ms 5892 KB Correct
25 Correct 57 ms 5988 KB Correct
26 Correct 76 ms 7836 KB Correct
27 Correct 80 ms 7952 KB Correct
28 Correct 80 ms 7764 KB Correct
29 Correct 87 ms 8100 KB Correct
30 Correct 83 ms 8080 KB Correct
31 Correct 81 ms 7788 KB Correct
32 Correct 84 ms 7892 KB Correct
33 Correct 86 ms 7760 KB Correct
34 Correct 72 ms 8012 KB Correct
35 Correct 84 ms 7836 KB Correct
36 Correct 82 ms 7960 KB Correct
37 Correct 69 ms 7944 KB Correct
38 Correct 79 ms 7756 KB Correct
39 Correct 88 ms 7664 KB Correct
40 Correct 89 ms 8096 KB Correct
41 Correct 82 ms 7888 KB Correct
42 Correct 81 ms 7764 KB Correct
43 Correct 86 ms 7764 KB Correct
44 Correct 74 ms 7968 KB Correct
45 Correct 84 ms 8020 KB Correct
46 Correct 82 ms 8092 KB Correct
47 Correct 80 ms 8092 KB Correct
48 Correct 84 ms 7760 KB Correct
49 Correct 80 ms 8096 KB Correct
50 Correct 84 ms 8100 KB Correct
51 Correct 79 ms 7964 KB Correct
52 Correct 81 ms 8032 KB Correct
53 Correct 82 ms 7836 KB Correct
54 Correct 78 ms 8008 KB Correct
55 Correct 81 ms 7820 KB Correct
56 Correct 78 ms 8100 KB Correct
57 Correct 77 ms 7836 KB Correct
58 Correct 80 ms 8096 KB Correct
59 Correct 75 ms 8096 KB Correct
60 Correct 78 ms 8024 KB Correct
61 Correct 70 ms 8016 KB Correct
62 Correct 83 ms 8092 KB Correct
63 Correct 86 ms 8012 KB Correct
64 Correct 82 ms 8024 KB Correct
65 Correct 74 ms 8012 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 776 KB Correct
2 Correct 210 ms 11500 KB Correct
3 Correct 216 ms 11656 KB Correct
4 Correct 125 ms 12308 KB Correct
5 Correct 114 ms 12996 KB Correct
6 Correct 216 ms 12724 KB Correct
7 Correct 88 ms 12972 KB Correct
8 Correct 84 ms 11404 KB Correct
9 Correct 212 ms 12128 KB Correct
10 Correct 232 ms 12348 KB Correct
11 Correct 170 ms 11896 KB Correct
12 Correct 107 ms 13212 KB Correct
13 Correct 273 ms 12052 KB Correct
14 Correct 92 ms 11352 KB Correct
15 Correct 88 ms 11612 KB Correct
16 Correct 230 ms 12336 KB Correct
17 Correct 240 ms 13212 KB Correct
18 Correct 121 ms 11348 KB Correct
19 Correct 105 ms 11628 KB Correct
20 Correct 160 ms 11120 KB Correct
21 Correct 94 ms 12536 KB Correct
22 Correct 88 ms 11868 KB Correct
23 Correct 211 ms 12124 KB Correct
24 Correct 202 ms 11920 KB Correct
25 Correct 92 ms 11428 KB Correct
26 Correct 98 ms 12376 KB Correct
27 Correct 95 ms 11116 KB Correct
28 Correct 92 ms 11612 KB Correct
29 Correct 83 ms 12112 KB Correct
30 Correct 209 ms 12092 KB Correct
31 Correct 250 ms 11352 KB Correct
32 Correct 98 ms 12640 KB Correct
33 Correct 239 ms 11968 KB Correct
34 Correct 237 ms 12548 KB Correct
35 Correct 90 ms 11424 KB Correct
36 Correct 89 ms 11164 KB Correct
37 Correct 223 ms 12132 KB Correct
38 Correct 249 ms 12040 KB Correct
39 Correct 279 ms 12664 KB Correct
40 Correct 148 ms 12968 KB Correct
41 Correct 222 ms 12636 KB Correct
42 Correct 92 ms 12380 KB Correct
43 Correct 88 ms 12128 KB Correct
44 Correct 238 ms 11832 KB Correct
45 Correct 207 ms 11168 KB Correct
46 Correct 105 ms 11764 KB Correct
47 Correct 101 ms 11680 KB Correct
48 Correct 99 ms 12272 KB Correct
49 Correct 89 ms 10916 KB Correct
50 Correct 88 ms 12368 KB Correct
51 Correct 81 ms 7844 KB Correct
52 Correct 83 ms 7840 KB Correct
53 Correct 83 ms 8144 KB Correct
54 Correct 99 ms 10328 KB Correct
55 Correct 143 ms 10004 KB Correct
56 Correct 186 ms 10224 KB Correct
57 Correct 78 ms 7584 KB Correct
58 Correct 79 ms 7508 KB Correct
59 Correct 80 ms 7492 KB Correct
60 Correct 76 ms 7516 KB Correct
61 Correct 82 ms 7776 KB Correct
62 Correct 84 ms 7836 KB Correct
63 Correct 80 ms 7584 KB Correct
64 Correct 62 ms 5880 KB Correct
65 Correct 57 ms 5968 KB Correct
66 Correct 76 ms 7500 KB Correct
67 Correct 77 ms 7688 KB Correct
68 Correct 84 ms 7560 KB Correct
69 Correct 88 ms 7752 KB Correct
70 Correct 54 ms 5924 KB Correct
71 Correct 63 ms 5876 KB Correct
72 Correct 55 ms 5900 KB Correct
73 Correct 71 ms 5960 KB Correct
74 Correct 62 ms 5892 KB Correct
75 Correct 57 ms 5988 KB Correct
76 Correct 76 ms 7836 KB Correct
77 Correct 80 ms 7952 KB Correct
78 Correct 80 ms 7764 KB Correct
79 Correct 87 ms 8100 KB Correct
80 Correct 83 ms 8080 KB Correct
81 Correct 81 ms 7788 KB Correct
82 Correct 84 ms 7892 KB Correct
83 Correct 86 ms 7760 KB Correct
84 Correct 72 ms 8012 KB Correct
85 Correct 84 ms 7836 KB Correct
86 Correct 82 ms 7960 KB Correct
87 Correct 69 ms 7944 KB Correct
88 Correct 79 ms 7756 KB Correct
89 Correct 88 ms 7664 KB Correct
90 Correct 89 ms 8096 KB Correct
91 Correct 82 ms 7888 KB Correct
92 Correct 81 ms 7764 KB Correct
93 Correct 86 ms 7764 KB Correct
94 Correct 74 ms 7968 KB Correct
95 Correct 84 ms 8020 KB Correct
96 Correct 82 ms 8092 KB Correct
97 Correct 80 ms 8092 KB Correct
98 Correct 84 ms 7760 KB Correct
99 Correct 80 ms 8096 KB Correct
100 Correct 84 ms 8100 KB Correct
101 Correct 79 ms 7964 KB Correct
102 Correct 81 ms 8032 KB Correct
103 Correct 82 ms 7836 KB Correct
104 Correct 78 ms 8008 KB Correct
105 Correct 81 ms 7820 KB Correct
106 Correct 78 ms 8100 KB Correct
107 Correct 77 ms 7836 KB Correct
108 Correct 80 ms 8096 KB Correct
109 Correct 75 ms 8096 KB Correct
110 Correct 78 ms 8024 KB Correct
111 Correct 70 ms 8016 KB Correct
112 Correct 83 ms 8092 KB Correct
113 Correct 86 ms 8012 KB Correct
114 Correct 82 ms 8024 KB Correct
115 Correct 74 ms 8012 KB Correct
116 Correct 79 ms 7960 KB Correct
117 Correct 79 ms 8116 KB Correct
118 Correct 92 ms 8032 KB Correct
119 Correct 96 ms 7768 KB Correct
120 Correct 75 ms 7968 KB Correct
121 Correct 82 ms 7860 KB Correct
122 Correct 80 ms 7772 KB Correct
123 Correct 97 ms 10344 KB Correct
124 Correct 147 ms 9936 KB Correct
125 Correct 174 ms 9884 KB Correct
126 Correct 80 ms 7592 KB Correct
127 Correct 89 ms 7696 KB Correct
128 Correct 81 ms 7832 KB Correct
129 Correct 79 ms 7504 KB Correct
130 Correct 78 ms 7840 KB Correct
131 Correct 76 ms 7840 KB Correct
132 Correct 78 ms 7840 KB Correct
133 Correct 60 ms 5980 KB Correct
134 Correct 53 ms 5796 KB Correct
135 Correct 76 ms 7584 KB Correct
136 Correct 83 ms 7672 KB Correct
137 Correct 71 ms 7508 KB Correct
138 Correct 73 ms 7684 KB Correct
139 Correct 55 ms 5784 KB Correct
140 Correct 64 ms 6136 KB Correct
141 Correct 63 ms 6020 KB Correct
142 Correct 64 ms 5888 KB Correct
143 Correct 54 ms 5796 KB Correct
144 Correct 63 ms 5980 KB Correct
145 Correct 88 ms 8020 KB Correct
146 Correct 79 ms 8304 KB Correct
147 Correct 80 ms 8012 KB Correct
148 Correct 82 ms 7852 KB Correct
149 Correct 71 ms 8076 KB Correct
150 Correct 89 ms 7924 KB Correct
151 Correct 87 ms 7932 KB Correct
152 Correct 83 ms 7960 KB Correct
153 Correct 86 ms 7836 KB Correct
154 Correct 80 ms 8012 KB Correct
155 Correct 84 ms 7844 KB Correct
156 Correct 84 ms 7780 KB Correct
157 Correct 75 ms 8020 KB Correct
158 Correct 80 ms 8040 KB Correct
159 Correct 80 ms 7952 KB Correct
160 Correct 76 ms 8036 KB Correct
161 Correct 78 ms 7664 KB Correct
162 Correct 86 ms 7836 KB Correct
163 Correct 84 ms 8096 KB Correct
164 Correct 82 ms 7688 KB Correct
165 Correct 84 ms 7764 KB Correct
166 Correct 75 ms 8012 KB Correct
167 Correct 80 ms 8088 KB Correct
168 Correct 86 ms 7948 KB Correct
169 Correct 80 ms 8012 KB Correct
170 Correct 69 ms 7836 KB Correct
171 Correct 87 ms 7972 KB Correct
172 Correct 81 ms 7756 KB Correct
173 Correct 84 ms 7772 KB Correct
174 Correct 75 ms 7764 KB Correct
175 Correct 87 ms 8028 KB Correct
176 Correct 81 ms 8028 KB Correct
177 Correct 80 ms 8024 KB Correct
178 Correct 79 ms 8032 KB Correct
179 Correct 79 ms 7916 KB Correct
180 Correct 80 ms 7988 KB Correct
181 Correct 77 ms 8096 KB Correct
182 Correct 74 ms 8016 KB Correct
183 Correct 83 ms 7956 KB Correct
184 Correct 82 ms 8016 KB Correct
185 Correct 230 ms 11492 KB Correct
186 Correct 210 ms 11864 KB Correct
187 Correct 125 ms 12364 KB Correct
188 Correct 98 ms 13064 KB Correct
189 Correct 218 ms 12580 KB Correct
190 Correct 90 ms 12704 KB Correct
191 Correct 94 ms 11764 KB Correct
192 Correct 221 ms 12044 KB Correct
193 Correct 218 ms 12380 KB Correct
194 Correct 166 ms 11644 KB Correct
195 Correct 109 ms 13140 KB Correct
196 Correct 281 ms 11900 KB Correct
197 Correct 87 ms 11424 KB Correct
198 Correct 95 ms 11692 KB Correct
199 Correct 223 ms 12400 KB Correct
200 Correct 218 ms 13472 KB Correct
201 Correct 135 ms 11244 KB Correct
202 Correct 103 ms 11856 KB Correct
203 Correct 179 ms 11128 KB Correct
204 Correct 93 ms 12372 KB Correct
205 Correct 90 ms 11868 KB Correct
206 Correct 209 ms 11932 KB Correct
207 Correct 245 ms 11972 KB Correct
208 Correct 113 ms 11420 KB Correct
209 Correct 91 ms 12448 KB Correct
210 Correct 98 ms 11420 KB Correct
211 Correct 90 ms 11552 KB Correct
212 Correct 91 ms 12132 KB Correct
213 Correct 216 ms 12092 KB Correct
214 Correct 239 ms 11260 KB Correct
215 Correct 94 ms 12636 KB Correct
216 Correct 231 ms 11904 KB Correct
217 Correct 274 ms 12240 KB Correct
218 Correct 89 ms 11428 KB Correct
219 Correct 92 ms 11196 KB Correct
220 Correct 224 ms 11976 KB Correct
221 Correct 207 ms 12060 KB Correct
222 Correct 275 ms 13208 KB Correct
223 Correct 177 ms 12924 KB Correct
224 Correct 211 ms 12436 KB Correct
225 Correct 90 ms 12312 KB Correct
226 Correct 92 ms 12188 KB Correct
227 Correct 237 ms 12368 KB Correct
228 Correct 233 ms 11028 KB Correct
229 Correct 101 ms 11540 KB Correct
230 Correct 98 ms 11620 KB Correct
231 Correct 103 ms 12360 KB Correct
232 Correct 101 ms 11376 KB Correct
233 Correct 88 ms 12568 KB Correct
234 Correct 97 ms 10188 KB Correct
235 Correct 113 ms 9976 KB Correct
236 Correct 63 ms 5952 KB Correct
237 Correct 60 ms 5940 KB Correct
238 Correct 57 ms 5876 KB Correct
239 Correct 46 ms 4548 KB Correct
240 Correct 78 ms 8016 KB Correct
241 Correct 74 ms 7836 KB Correct
242 Correct 79 ms 8032 KB Correct
243 Correct 84 ms 7872 KB Correct
244 Correct 91 ms 8036 KB Correct
245 Correct 87 ms 8120 KB Correct
246 Correct 88 ms 7952 KB Correct
247 Correct 80 ms 7840 KB Correct
248 Correct 90 ms 7756 KB Correct
249 Correct 84 ms 7836 KB Correct
250 Correct 76 ms 7836 KB Correct
251 Correct 81 ms 8028 KB Correct
252 Correct 77 ms 8040 KB Correct
253 Correct 76 ms 8100 KB Correct
254 Correct 77 ms 7964 KB Correct
255 Correct 78 ms 7760 KB Correct
256 Correct 81 ms 7940 KB Correct
257 Correct 78 ms 8028 KB Correct
258 Correct 84 ms 8040 KB Correct
259 Correct 78 ms 7776 KB Correct
260 Correct 81 ms 7768 KB Correct
261 Correct 76 ms 7856 KB Correct
262 Correct 87 ms 7912 KB Correct
263 Correct 82 ms 7796 KB Correct
264 Correct 82 ms 8032 KB Correct
265 Correct 57 ms 5948 KB Correct
266 Correct 63 ms 5868 KB Correct
267 Correct 62 ms 5868 KB Correct
268 Correct 55 ms 5880 KB Correct
269 Correct 61 ms 6168 KB Correct
270 Correct 54 ms 5796 KB Correct
271 Correct 56 ms 5884 KB Correct
272 Correct 64 ms 6152 KB Correct
273 Correct 63 ms 5892 KB Correct
274 Correct 47 ms 5888 KB Correct
275 Correct 55 ms 5800 KB Correct
276 Correct 65 ms 5880 KB Correct
277 Correct 61 ms 5800 KB Correct
278 Correct 64 ms 5980 KB Correct
279 Correct 53 ms 5872 KB Correct
280 Correct 82 ms 8092 KB Correct
281 Correct 87 ms 8032 KB Correct
282 Correct 76 ms 7956 KB Correct
283 Correct 82 ms 7764 KB Correct
284 Correct 81 ms 8260 KB Correct
285 Correct 82 ms 8020 KB Correct
286 Correct 83 ms 8028 KB Correct
287 Correct 84 ms 8012 KB Correct
288 Correct 83 ms 8100 KB Correct
289 Correct 91 ms 8092 KB Correct