답안 #1065030

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1065030 2024-08-18T21:28:41 Z beaconmc The Ties That Guide Us (CEOI23_incursion) C++17
60 / 100
262 ms 15520 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(1, -1, 0);

    ll cent = centfind(1, -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 || edges[curr].size()==1) 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 4364 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 215 ms 13372 KB Correct
2 Correct 217 ms 13820 KB Correct
3 Correct 132 ms 14416 KB Correct
4 Correct 108 ms 15272 KB Correct
5 Correct 195 ms 14736 KB Correct
6 Correct 80 ms 14956 KB Correct
7 Correct 80 ms 13296 KB Correct
8 Correct 186 ms 13652 KB Correct
9 Correct 219 ms 14328 KB Correct
10 Correct 160 ms 13404 KB Correct
11 Correct 100 ms 15092 KB Correct
12 Correct 262 ms 13820 KB Correct
13 Correct 88 ms 12948 KB Correct
14 Correct 92 ms 13556 KB Correct
15 Correct 213 ms 14324 KB Correct
16 Correct 206 ms 15520 KB Correct
17 Correct 118 ms 12776 KB Correct
18 Correct 90 ms 13104 KB Correct
19 Correct 154 ms 12632 KB Correct
20 Correct 84 ms 14492 KB Correct
21 Correct 84 ms 13476 KB Correct
22 Correct 220 ms 13788 KB Correct
23 Correct 214 ms 13872 KB Correct
24 Correct 100 ms 13468 KB Correct
25 Correct 90 ms 14240 KB Correct
26 Correct 83 ms 13052 KB Correct
27 Correct 72 ms 13676 KB Correct
28 Correct 81 ms 14080 KB Correct
29 Correct 209 ms 14048 KB Correct
30 Correct 215 ms 13052 KB Correct
31 Correct 90 ms 15188 KB Correct
32 Correct 233 ms 14180 KB Correct
33 Correct 243 ms 14508 KB Correct
34 Correct 79 ms 12956 KB Correct
35 Correct 73 ms 12696 KB Correct
36 Correct 200 ms 13964 KB Correct
37 Correct 211 ms 14172 KB Correct
38 Correct 256 ms 14680 KB Correct
39 Correct 148 ms 15264 KB Correct
40 Correct 201 ms 14956 KB Correct
41 Correct 79 ms 14228 KB Correct
42 Correct 91 ms 13816 KB Correct
43 Correct 216 ms 14168 KB Correct
44 Correct 225 ms 12380 KB Correct
45 Correct 90 ms 13216 KB Correct
46 Correct 92 ms 13700 KB Correct
47 Correct 109 ms 14332 KB Correct
48 Correct 83 ms 12548 KB Correct
49 Correct 92 ms 14752 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 86 ms 8780 KB Correct
2 Correct 73 ms 8792 KB Correct
3 Correct 80 ms 8860 KB Correct
4 Correct 86 ms 11992 KB Correct
5 Correct 134 ms 11244 KB Correct
6 Correct 163 ms 11504 KB Correct
7 Correct 74 ms 8692 KB Correct
8 Correct 78 ms 9120 KB Correct
9 Correct 76 ms 8696 KB Correct
10 Correct 76 ms 8688 KB Correct
11 Correct 76 ms 8536 KB Correct
12 Correct 73 ms 8452 KB Correct
13 Correct 74 ms 8704 KB Correct
14 Correct 54 ms 7336 KB Correct
15 Correct 60 ms 7332 KB Correct
16 Correct 75 ms 8692 KB Correct
17 Correct 77 ms 8432 KB Correct
18 Correct 73 ms 8600 KB Correct
19 Correct 79 ms 8700 KB Correct
20 Correct 55 ms 7324 KB Correct
21 Correct 57 ms 7324 KB Correct
22 Correct 53 ms 7340 KB Correct
23 Correct 62 ms 7340 KB Correct
24 Correct 59 ms 7368 KB Correct
25 Correct 54 ms 7332 KB Correct
26 Correct 79 ms 8808 KB Correct
27 Correct 80 ms 8868 KB Correct
28 Correct 83 ms 8684 KB Correct
29 Correct 77 ms 8700 KB Correct
30 Correct 76 ms 8940 KB Correct
31 Correct 77 ms 8684 KB Correct
32 Correct 81 ms 8712 KB Correct
33 Correct 70 ms 8700 KB Correct
34 Correct 83 ms 8604 KB Correct
35 Correct 77 ms 8872 KB Correct
36 Correct 72 ms 8972 KB Correct
37 Correct 92 ms 8844 KB Correct
38 Correct 80 ms 8696 KB Correct
39 Correct 69 ms 8444 KB Correct
40 Correct 84 ms 8684 KB Correct
41 Correct 80 ms 8720 KB Correct
42 Correct 73 ms 8708 KB Correct
43 Correct 72 ms 9104 KB Correct
44 Correct 76 ms 8860 KB Correct
45 Correct 82 ms 8736 KB Correct
46 Correct 80 ms 9380 KB Correct
47 Correct 71 ms 9212 KB Correct
48 Correct 82 ms 8692 KB Correct
49 Correct 78 ms 8436 KB Correct
50 Correct 83 ms 8696 KB Correct
51 Correct 78 ms 8860 KB Correct
52 Correct 78 ms 8700 KB Correct
53 Correct 78 ms 8692 KB Correct
54 Correct 76 ms 8960 KB Correct
55 Correct 80 ms 8696 KB Correct
56 Correct 77 ms 8944 KB Correct
57 Correct 74 ms 8696 KB Correct
58 Correct 77 ms 8972 KB Correct
59 Correct 77 ms 8860 KB Correct
60 Correct 81 ms 8684 KB Correct
61 Correct 78 ms 8916 KB Correct
62 Correct 83 ms 8960 KB Correct
63 Correct 80 ms 8964 KB Correct
64 Correct 74 ms 8868 KB Correct
65 Correct 78 ms 8948 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4364 KB Correct
2 Correct 215 ms 13372 KB Correct
3 Correct 217 ms 13820 KB Correct
4 Correct 132 ms 14416 KB Correct
5 Correct 108 ms 15272 KB Correct
6 Correct 195 ms 14736 KB Correct
7 Correct 80 ms 14956 KB Correct
8 Correct 80 ms 13296 KB Correct
9 Correct 186 ms 13652 KB Correct
10 Correct 219 ms 14328 KB Correct
11 Correct 160 ms 13404 KB Correct
12 Correct 100 ms 15092 KB Correct
13 Correct 262 ms 13820 KB Correct
14 Correct 88 ms 12948 KB Correct
15 Correct 92 ms 13556 KB Correct
16 Correct 213 ms 14324 KB Correct
17 Correct 206 ms 15520 KB Correct
18 Correct 118 ms 12776 KB Correct
19 Correct 90 ms 13104 KB Correct
20 Correct 154 ms 12632 KB Correct
21 Correct 84 ms 14492 KB Correct
22 Correct 84 ms 13476 KB Correct
23 Correct 220 ms 13788 KB Correct
24 Correct 214 ms 13872 KB Correct
25 Correct 100 ms 13468 KB Correct
26 Correct 90 ms 14240 KB Correct
27 Correct 83 ms 13052 KB Correct
28 Correct 72 ms 13676 KB Correct
29 Correct 81 ms 14080 KB Correct
30 Correct 209 ms 14048 KB Correct
31 Correct 215 ms 13052 KB Correct
32 Correct 90 ms 15188 KB Correct
33 Correct 233 ms 14180 KB Correct
34 Correct 243 ms 14508 KB Correct
35 Correct 79 ms 12956 KB Correct
36 Correct 73 ms 12696 KB Correct
37 Correct 200 ms 13964 KB Correct
38 Correct 211 ms 14172 KB Correct
39 Correct 256 ms 14680 KB Correct
40 Correct 148 ms 15264 KB Correct
41 Correct 201 ms 14956 KB Correct
42 Correct 79 ms 14228 KB Correct
43 Correct 91 ms 13816 KB Correct
44 Correct 216 ms 14168 KB Correct
45 Correct 225 ms 12380 KB Correct
46 Correct 90 ms 13216 KB Correct
47 Correct 92 ms 13700 KB Correct
48 Correct 109 ms 14332 KB Correct
49 Correct 83 ms 12548 KB Correct
50 Correct 92 ms 14752 KB Correct
51 Correct 86 ms 8780 KB Correct
52 Correct 73 ms 8792 KB Correct
53 Correct 80 ms 8860 KB Correct
54 Correct 86 ms 11992 KB Correct
55 Correct 134 ms 11244 KB Correct
56 Correct 163 ms 11504 KB Correct
57 Correct 74 ms 8692 KB Correct
58 Correct 78 ms 9120 KB Correct
59 Correct 76 ms 8696 KB Correct
60 Correct 76 ms 8688 KB Correct
61 Correct 76 ms 8536 KB Correct
62 Correct 73 ms 8452 KB Correct
63 Correct 74 ms 8704 KB Correct
64 Correct 54 ms 7336 KB Correct
65 Correct 60 ms 7332 KB Correct
66 Correct 75 ms 8692 KB Correct
67 Correct 77 ms 8432 KB Correct
68 Correct 73 ms 8600 KB Correct
69 Correct 79 ms 8700 KB Correct
70 Correct 55 ms 7324 KB Correct
71 Correct 57 ms 7324 KB Correct
72 Correct 53 ms 7340 KB Correct
73 Correct 62 ms 7340 KB Correct
74 Correct 59 ms 7368 KB Correct
75 Correct 54 ms 7332 KB Correct
76 Correct 79 ms 8808 KB Correct
77 Correct 80 ms 8868 KB Correct
78 Correct 83 ms 8684 KB Correct
79 Correct 77 ms 8700 KB Correct
80 Correct 76 ms 8940 KB Correct
81 Correct 77 ms 8684 KB Correct
82 Correct 81 ms 8712 KB Correct
83 Correct 70 ms 8700 KB Correct
84 Correct 83 ms 8604 KB Correct
85 Correct 77 ms 8872 KB Correct
86 Correct 72 ms 8972 KB Correct
87 Correct 92 ms 8844 KB Correct
88 Correct 80 ms 8696 KB Correct
89 Correct 69 ms 8444 KB Correct
90 Correct 84 ms 8684 KB Correct
91 Correct 80 ms 8720 KB Correct
92 Correct 73 ms 8708 KB Correct
93 Correct 72 ms 9104 KB Correct
94 Correct 76 ms 8860 KB Correct
95 Correct 82 ms 8736 KB Correct
96 Correct 80 ms 9380 KB Correct
97 Correct 71 ms 9212 KB Correct
98 Correct 82 ms 8692 KB Correct
99 Correct 78 ms 8436 KB Correct
100 Correct 83 ms 8696 KB Correct
101 Correct 78 ms 8860 KB Correct
102 Correct 78 ms 8700 KB Correct
103 Correct 78 ms 8692 KB Correct
104 Correct 76 ms 8960 KB Correct
105 Correct 80 ms 8696 KB Correct
106 Correct 77 ms 8944 KB Correct
107 Correct 74 ms 8696 KB Correct
108 Correct 77 ms 8972 KB Correct
109 Correct 77 ms 8860 KB Correct
110 Correct 81 ms 8684 KB Correct
111 Correct 78 ms 8916 KB Correct
112 Correct 83 ms 8960 KB Correct
113 Correct 80 ms 8964 KB Correct
114 Correct 74 ms 8868 KB Correct
115 Correct 78 ms 8948 KB Correct
116 Correct 84 ms 8864 KB Correct
117 Correct 89 ms 8952 KB Correct
118 Correct 88 ms 9076 KB Correct
119 Correct 82 ms 8964 KB Correct
120 Correct 78 ms 8616 KB Correct
121 Correct 87 ms 8964 KB Correct
122 Correct 80 ms 8888 KB Correct
123 Correct 101 ms 12192 KB Correct
124 Correct 142 ms 11260 KB Correct
125 Correct 163 ms 11268 KB Correct
126 Correct 79 ms 8864 KB Correct
127 Correct 77 ms 8532 KB Correct
128 Correct 73 ms 8860 KB Correct
129 Correct 76 ms 8440 KB Correct
130 Correct 76 ms 8608 KB Correct
131 Correct 79 ms 8520 KB Correct
132 Correct 86 ms 8600 KB Correct
133 Correct 61 ms 7336 KB Correct
134 Correct 60 ms 7336 KB Correct
135 Correct 74 ms 8532 KB Correct
136 Correct 78 ms 8444 KB Correct
137 Correct 79 ms 8440 KB Correct
138 Correct 79 ms 8348 KB Correct
139 Correct 57 ms 7516 KB Correct
140 Correct 54 ms 7308 KB Correct
141 Correct 60 ms 7320 KB Correct
142 Correct 54 ms 7344 KB Correct
143 Correct 50 ms 7320 KB Correct
144 Correct 66 ms 7324 KB Correct
145 Correct 90 ms 8864 KB Correct
146 Correct 75 ms 8516 KB Correct
147 Correct 87 ms 8580 KB Correct
148 Correct 82 ms 8420 KB Correct
149 Correct 86 ms 8932 KB Correct
150 Correct 80 ms 8924 KB Correct
151 Correct 88 ms 8944 KB Correct
152 Correct 73 ms 8516 KB Correct
153 Correct 91 ms 8692 KB Correct
154 Correct 84 ms 8708 KB Correct
155 Correct 80 ms 8688 KB Correct
156 Correct 86 ms 8516 KB Correct
157 Correct 74 ms 8856 KB Correct
158 Correct 82 ms 8848 KB Correct
159 Correct 92 ms 8860 KB Correct
160 Correct 82 ms 8528 KB Correct
161 Correct 71 ms 8772 KB Correct
162 Correct 88 ms 8708 KB Correct
163 Correct 79 ms 8860 KB Correct
164 Correct 84 ms 8700 KB Correct
165 Correct 92 ms 8936 KB Correct
166 Correct 94 ms 8932 KB Correct
167 Correct 83 ms 8860 KB Correct
168 Correct 71 ms 8688 KB Correct
169 Correct 81 ms 8860 KB Correct
170 Correct 83 ms 9120 KB Correct
171 Correct 80 ms 8860 KB Correct
172 Correct 77 ms 8604 KB Correct
173 Correct 72 ms 8860 KB Correct
174 Correct 77 ms 8860 KB Correct
175 Correct 95 ms 8952 KB Correct
176 Correct 61 ms 8688 KB Correct
177 Correct 71 ms 8764 KB Correct
178 Correct 86 ms 8860 KB Correct
179 Correct 76 ms 8860 KB Correct
180 Correct 89 ms 8928 KB Correct
181 Correct 79 ms 8860 KB Correct
182 Correct 80 ms 8684 KB Correct
183 Correct 71 ms 8860 KB Correct
184 Correct 75 ms 8764 KB Correct
185 Correct 208 ms 13352 KB Correct
186 Correct 216 ms 13604 KB Correct
187 Correct 123 ms 14364 KB Correct
188 Correct 106 ms 15068 KB Correct
189 Correct 197 ms 15104 KB Correct
190 Correct 84 ms 14760 KB Correct
191 Correct 84 ms 13308 KB Correct
192 Correct 209 ms 13656 KB Correct
193 Correct 232 ms 14360 KB Correct
194 Correct 162 ms 13312 KB Correct
195 Correct 112 ms 15360 KB Correct
196 Correct 262 ms 13564 KB Correct
197 Correct 84 ms 12956 KB Correct
198 Correct 77 ms 13340 KB Correct
199 Correct 222 ms 14352 KB Correct
200 Correct 207 ms 15436 KB Correct
201 Correct 122 ms 12712 KB Correct
202 Correct 89 ms 13312 KB Correct
203 Correct 155 ms 12960 KB Correct
204 Correct 84 ms 14496 KB Correct
205 Correct 79 ms 13304 KB Correct
206 Correct 235 ms 13860 KB Correct
207 Correct 247 ms 13956 KB Correct
208 Correct 109 ms 13312 KB Correct
209 Correct 91 ms 14068 KB Correct
210 Correct 93 ms 13292 KB Correct
211 Correct 87 ms 13232 KB Correct
212 Correct 100 ms 14036 KB Correct
213 Correct 218 ms 14184 KB Correct
214 Correct 234 ms 13040 KB Correct
215 Correct 93 ms 15004 KB Correct
216 Correct 258 ms 13996 KB Correct
217 Correct 255 ms 14232 KB Correct
218 Correct 84 ms 12956 KB Correct
219 Correct 84 ms 12960 KB Correct
220 Correct 223 ms 13820 KB Correct
221 Correct 225 ms 14076 KB Correct
222 Correct 218 ms 14688 KB Correct
223 Correct 131 ms 15080 KB Correct
224 Correct 196 ms 14756 KB Correct
225 Correct 83 ms 14284 KB Correct
226 Correct 83 ms 13656 KB Correct
227 Correct 203 ms 14236 KB Correct
228 Correct 237 ms 12728 KB Correct
229 Correct 96 ms 13212 KB Correct
230 Correct 93 ms 13472 KB Correct
231 Correct 98 ms 14240 KB Correct
232 Correct 83 ms 12436 KB Correct
233 Correct 92 ms 14416 KB Correct
234 Correct 93 ms 11508 KB Correct
235 Correct 109 ms 11432 KB Correct
236 Correct 54 ms 7332 KB Correct
237 Correct 65 ms 7336 KB Correct
238 Correct 61 ms 7340 KB Correct
239 Correct 50 ms 6752 KB Correct
240 Correct 67 ms 8704 KB Correct
241 Correct 82 ms 8452 KB Correct
242 Correct 90 ms 8604 KB Correct
243 Correct 67 ms 8516 KB Correct
244 Correct 83 ms 8688 KB Correct
245 Correct 78 ms 8704 KB Correct
246 Correct 81 ms 8448 KB Correct
247 Correct 76 ms 8860 KB Correct
248 Correct 78 ms 8700 KB Correct
249 Correct 75 ms 8704 KB Correct
250 Correct 75 ms 8860 KB Correct
251 Correct 78 ms 8492 KB Correct
252 Correct 76 ms 8612 KB Correct
253 Correct 74 ms 8528 KB Correct
254 Correct 81 ms 8924 KB Correct
255 Correct 73 ms 8684 KB Correct
256 Correct 77 ms 8600 KB Correct
257 Correct 73 ms 8424 KB Correct
258 Correct 76 ms 8952 KB Correct
259 Correct 82 ms 8700 KB Correct
260 Correct 83 ms 8532 KB Correct
261 Correct 75 ms 8692 KB Correct
262 Correct 78 ms 8860 KB Correct
263 Correct 78 ms 8864 KB Correct
264 Correct 78 ms 8880 KB Correct
265 Incorrect 53 ms 7336 KB Not correct
266 Halted 0 ms 0 KB -