답안 #1065023

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1065023 2024-08-18T21:26:29 Z beaconmc The Ties That Guide Us (CEOI23_incursion) C++17
60 / 100
295 ms 15648 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) 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 218 ms 13212 KB Correct
2 Correct 209 ms 13544 KB Correct
3 Correct 107 ms 14588 KB Correct
4 Correct 116 ms 15104 KB Correct
5 Correct 215 ms 14820 KB Correct
6 Correct 84 ms 14980 KB Correct
7 Correct 89 ms 13312 KB Correct
8 Correct 223 ms 13912 KB Correct
9 Correct 217 ms 14588 KB Correct
10 Correct 152 ms 13592 KB Correct
11 Correct 103 ms 15388 KB Correct
12 Correct 265 ms 13780 KB Correct
13 Correct 81 ms 13212 KB Correct
14 Correct 82 ms 13316 KB Correct
15 Correct 196 ms 14284 KB Correct
16 Correct 223 ms 15648 KB Correct
17 Correct 129 ms 12700 KB Correct
18 Correct 105 ms 13544 KB Correct
19 Correct 162 ms 12700 KB Correct
20 Correct 90 ms 14688 KB Correct
21 Correct 88 ms 13544 KB Correct
22 Correct 243 ms 13632 KB Correct
23 Correct 217 ms 13976 KB Correct
24 Correct 99 ms 13380 KB Correct
25 Correct 94 ms 14284 KB Correct
26 Correct 96 ms 13048 KB Correct
27 Correct 84 ms 13576 KB Correct
28 Correct 72 ms 14080 KB Correct
29 Correct 209 ms 14328 KB Correct
30 Correct 195 ms 12952 KB Correct
31 Correct 96 ms 15108 KB Correct
32 Correct 246 ms 13916 KB Correct
33 Correct 234 ms 14212 KB Correct
34 Correct 88 ms 12788 KB Correct
35 Correct 81 ms 12616 KB Correct
36 Correct 216 ms 14096 KB Correct
37 Correct 216 ms 14072 KB Correct
38 Correct 252 ms 14844 KB Correct
39 Correct 153 ms 15260 KB Correct
40 Correct 203 ms 14748 KB Correct
41 Correct 86 ms 14076 KB Correct
42 Correct 87 ms 13968 KB Correct
43 Correct 222 ms 14076 KB Correct
44 Correct 218 ms 12636 KB Correct
45 Correct 87 ms 13560 KB Correct
46 Correct 84 ms 13824 KB Correct
47 Correct 95 ms 14240 KB Correct
48 Correct 81 ms 12448 KB Correct
49 Correct 90 ms 14324 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 8700 KB Correct
2 Correct 78 ms 9116 KB Correct
3 Correct 79 ms 8696 KB Correct
4 Correct 91 ms 12144 KB Correct
5 Correct 135 ms 11256 KB Correct
6 Correct 158 ms 11276 KB Correct
7 Correct 91 ms 8708 KB Correct
8 Correct 79 ms 8524 KB Correct
9 Correct 83 ms 8872 KB Correct
10 Correct 77 ms 8440 KB Correct
11 Correct 76 ms 8604 KB Correct
12 Correct 79 ms 8952 KB Correct
13 Correct 80 ms 8500 KB Correct
14 Correct 56 ms 7340 KB Correct
15 Correct 53 ms 7332 KB Correct
16 Correct 68 ms 8440 KB Correct
17 Correct 83 ms 8328 KB Correct
18 Correct 75 ms 8704 KB Correct
19 Correct 74 ms 8348 KB Correct
20 Correct 59 ms 7380 KB Correct
21 Correct 52 ms 7340 KB Correct
22 Correct 59 ms 7328 KB Correct
23 Correct 53 ms 7324 KB Correct
24 Correct 53 ms 7340 KB Correct
25 Correct 61 ms 7332 KB Correct
26 Correct 80 ms 8856 KB Correct
27 Correct 77 ms 8868 KB Correct
28 Correct 64 ms 8428 KB Correct
29 Correct 71 ms 8436 KB Correct
30 Correct 66 ms 8872 KB Correct
31 Correct 84 ms 8508 KB Correct
32 Correct 89 ms 8540 KB Correct
33 Correct 74 ms 8856 KB Correct
34 Correct 81 ms 8692 KB Correct
35 Correct 81 ms 8912 KB Correct
36 Correct 86 ms 8960 KB Correct
37 Correct 77 ms 8864 KB Correct
38 Correct 77 ms 8692 KB Correct
39 Correct 83 ms 8696 KB Correct
40 Correct 87 ms 8848 KB Correct
41 Correct 84 ms 8696 KB Correct
42 Correct 79 ms 8864 KB Correct
43 Correct 75 ms 8864 KB Correct
44 Correct 84 ms 8704 KB Correct
45 Correct 77 ms 9124 KB Correct
46 Correct 80 ms 8876 KB Correct
47 Correct 78 ms 9060 KB Correct
48 Correct 72 ms 8704 KB Correct
49 Correct 84 ms 8608 KB Correct
50 Correct 74 ms 9008 KB Correct
51 Correct 75 ms 8508 KB Correct
52 Correct 82 ms 8856 KB Correct
53 Correct 93 ms 8632 KB Correct
54 Correct 82 ms 8804 KB Correct
55 Correct 76 ms 8872 KB Correct
56 Correct 76 ms 9060 KB Correct
57 Correct 77 ms 8944 KB Correct
58 Correct 76 ms 8956 KB Correct
59 Correct 80 ms 8788 KB Correct
60 Correct 77 ms 8860 KB Correct
61 Correct 78 ms 8944 KB Correct
62 Correct 77 ms 8948 KB Correct
63 Correct 82 ms 8936 KB Correct
64 Correct 78 ms 9112 KB Correct
65 Correct 74 ms 8948 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4364 KB Correct
2 Correct 218 ms 13212 KB Correct
3 Correct 209 ms 13544 KB Correct
4 Correct 107 ms 14588 KB Correct
5 Correct 116 ms 15104 KB Correct
6 Correct 215 ms 14820 KB Correct
7 Correct 84 ms 14980 KB Correct
8 Correct 89 ms 13312 KB Correct
9 Correct 223 ms 13912 KB Correct
10 Correct 217 ms 14588 KB Correct
11 Correct 152 ms 13592 KB Correct
12 Correct 103 ms 15388 KB Correct
13 Correct 265 ms 13780 KB Correct
14 Correct 81 ms 13212 KB Correct
15 Correct 82 ms 13316 KB Correct
16 Correct 196 ms 14284 KB Correct
17 Correct 223 ms 15648 KB Correct
18 Correct 129 ms 12700 KB Correct
19 Correct 105 ms 13544 KB Correct
20 Correct 162 ms 12700 KB Correct
21 Correct 90 ms 14688 KB Correct
22 Correct 88 ms 13544 KB Correct
23 Correct 243 ms 13632 KB Correct
24 Correct 217 ms 13976 KB Correct
25 Correct 99 ms 13380 KB Correct
26 Correct 94 ms 14284 KB Correct
27 Correct 96 ms 13048 KB Correct
28 Correct 84 ms 13576 KB Correct
29 Correct 72 ms 14080 KB Correct
30 Correct 209 ms 14328 KB Correct
31 Correct 195 ms 12952 KB Correct
32 Correct 96 ms 15108 KB Correct
33 Correct 246 ms 13916 KB Correct
34 Correct 234 ms 14212 KB Correct
35 Correct 88 ms 12788 KB Correct
36 Correct 81 ms 12616 KB Correct
37 Correct 216 ms 14096 KB Correct
38 Correct 216 ms 14072 KB Correct
39 Correct 252 ms 14844 KB Correct
40 Correct 153 ms 15260 KB Correct
41 Correct 203 ms 14748 KB Correct
42 Correct 86 ms 14076 KB Correct
43 Correct 87 ms 13968 KB Correct
44 Correct 222 ms 14076 KB Correct
45 Correct 218 ms 12636 KB Correct
46 Correct 87 ms 13560 KB Correct
47 Correct 84 ms 13824 KB Correct
48 Correct 95 ms 14240 KB Correct
49 Correct 81 ms 12448 KB Correct
50 Correct 90 ms 14324 KB Correct
51 Correct 81 ms 8700 KB Correct
52 Correct 78 ms 9116 KB Correct
53 Correct 79 ms 8696 KB Correct
54 Correct 91 ms 12144 KB Correct
55 Correct 135 ms 11256 KB Correct
56 Correct 158 ms 11276 KB Correct
57 Correct 91 ms 8708 KB Correct
58 Correct 79 ms 8524 KB Correct
59 Correct 83 ms 8872 KB Correct
60 Correct 77 ms 8440 KB Correct
61 Correct 76 ms 8604 KB Correct
62 Correct 79 ms 8952 KB Correct
63 Correct 80 ms 8500 KB Correct
64 Correct 56 ms 7340 KB Correct
65 Correct 53 ms 7332 KB Correct
66 Correct 68 ms 8440 KB Correct
67 Correct 83 ms 8328 KB Correct
68 Correct 75 ms 8704 KB Correct
69 Correct 74 ms 8348 KB Correct
70 Correct 59 ms 7380 KB Correct
71 Correct 52 ms 7340 KB Correct
72 Correct 59 ms 7328 KB Correct
73 Correct 53 ms 7324 KB Correct
74 Correct 53 ms 7340 KB Correct
75 Correct 61 ms 7332 KB Correct
76 Correct 80 ms 8856 KB Correct
77 Correct 77 ms 8868 KB Correct
78 Correct 64 ms 8428 KB Correct
79 Correct 71 ms 8436 KB Correct
80 Correct 66 ms 8872 KB Correct
81 Correct 84 ms 8508 KB Correct
82 Correct 89 ms 8540 KB Correct
83 Correct 74 ms 8856 KB Correct
84 Correct 81 ms 8692 KB Correct
85 Correct 81 ms 8912 KB Correct
86 Correct 86 ms 8960 KB Correct
87 Correct 77 ms 8864 KB Correct
88 Correct 77 ms 8692 KB Correct
89 Correct 83 ms 8696 KB Correct
90 Correct 87 ms 8848 KB Correct
91 Correct 84 ms 8696 KB Correct
92 Correct 79 ms 8864 KB Correct
93 Correct 75 ms 8864 KB Correct
94 Correct 84 ms 8704 KB Correct
95 Correct 77 ms 9124 KB Correct
96 Correct 80 ms 8876 KB Correct
97 Correct 78 ms 9060 KB Correct
98 Correct 72 ms 8704 KB Correct
99 Correct 84 ms 8608 KB Correct
100 Correct 74 ms 9008 KB Correct
101 Correct 75 ms 8508 KB Correct
102 Correct 82 ms 8856 KB Correct
103 Correct 93 ms 8632 KB Correct
104 Correct 82 ms 8804 KB Correct
105 Correct 76 ms 8872 KB Correct
106 Correct 76 ms 9060 KB Correct
107 Correct 77 ms 8944 KB Correct
108 Correct 76 ms 8956 KB Correct
109 Correct 80 ms 8788 KB Correct
110 Correct 77 ms 8860 KB Correct
111 Correct 78 ms 8944 KB Correct
112 Correct 77 ms 8948 KB Correct
113 Correct 82 ms 8936 KB Correct
114 Correct 78 ms 9112 KB Correct
115 Correct 74 ms 8948 KB Correct
116 Correct 77 ms 8868 KB Correct
117 Correct 94 ms 8860 KB Correct
118 Correct 84 ms 8952 KB Correct
119 Correct 80 ms 9116 KB Correct
120 Correct 79 ms 8692 KB Correct
121 Correct 79 ms 8856 KB Correct
122 Correct 88 ms 8784 KB Correct
123 Correct 92 ms 12112 KB Correct
124 Correct 140 ms 11424 KB Correct
125 Correct 162 ms 11348 KB Correct
126 Correct 74 ms 8764 KB Correct
127 Correct 82 ms 8520 KB Correct
128 Correct 75 ms 8700 KB Correct
129 Correct 73 ms 8492 KB Correct
130 Correct 83 ms 8608 KB Correct
131 Correct 75 ms 8544 KB Correct
132 Correct 68 ms 8436 KB Correct
133 Correct 49 ms 7340 KB Correct
134 Correct 61 ms 7324 KB Correct
135 Correct 75 ms 8612 KB Correct
136 Correct 75 ms 8608 KB Correct
137 Correct 76 ms 8432 KB Correct
138 Correct 71 ms 8516 KB Correct
139 Correct 53 ms 7336 KB Correct
140 Correct 51 ms 7324 KB Correct
141 Correct 59 ms 7336 KB Correct
142 Correct 61 ms 7388 KB Correct
143 Correct 53 ms 7340 KB Correct
144 Correct 53 ms 7328 KB Correct
145 Correct 86 ms 9116 KB Correct
146 Correct 78 ms 8532 KB Correct
147 Correct 82 ms 8524 KB Correct
148 Correct 77 ms 8604 KB Correct
149 Correct 75 ms 8936 KB Correct
150 Correct 79 ms 8692 KB Correct
151 Correct 78 ms 8952 KB Correct
152 Correct 76 ms 8608 KB Correct
153 Correct 82 ms 8440 KB Correct
154 Correct 79 ms 8528 KB Correct
155 Correct 79 ms 9120 KB Correct
156 Correct 78 ms 8696 KB Correct
157 Correct 77 ms 8608 KB Correct
158 Correct 77 ms 8604 KB Correct
159 Correct 90 ms 8544 KB Correct
160 Correct 81 ms 8700 KB Correct
161 Correct 88 ms 8780 KB Correct
162 Correct 83 ms 8692 KB Correct
163 Correct 71 ms 8688 KB Correct
164 Correct 84 ms 8852 KB Correct
165 Correct 75 ms 9460 KB Correct
166 Correct 84 ms 8964 KB Correct
167 Correct 81 ms 8864 KB Correct
168 Correct 65 ms 8612 KB Correct
169 Correct 76 ms 8712 KB Correct
170 Correct 74 ms 8748 KB Correct
171 Correct 80 ms 9208 KB Correct
172 Correct 76 ms 8528 KB Correct
173 Correct 79 ms 9124 KB Correct
174 Correct 78 ms 8704 KB Correct
175 Correct 77 ms 9336 KB Correct
176 Correct 79 ms 8864 KB Correct
177 Correct 76 ms 8780 KB Correct
178 Correct 80 ms 8824 KB Correct
179 Correct 79 ms 8960 KB Correct
180 Correct 88 ms 8684 KB Correct
181 Correct 82 ms 8940 KB Correct
182 Correct 88 ms 8688 KB Correct
183 Correct 76 ms 8820 KB Correct
184 Correct 74 ms 8688 KB Correct
185 Correct 212 ms 13344 KB Correct
186 Correct 214 ms 13468 KB Correct
187 Correct 104 ms 14464 KB Correct
188 Correct 122 ms 15096 KB Correct
189 Correct 190 ms 14728 KB Correct
190 Correct 86 ms 14672 KB Correct
191 Correct 81 ms 13256 KB Correct
192 Correct 200 ms 13736 KB Correct
193 Correct 230 ms 14156 KB Correct
194 Correct 155 ms 13712 KB Correct
195 Correct 95 ms 15164 KB Correct
196 Correct 295 ms 13888 KB Correct
197 Correct 84 ms 13204 KB Correct
198 Correct 81 ms 13468 KB Correct
199 Correct 200 ms 14264 KB Correct
200 Correct 217 ms 15524 KB Correct
201 Correct 126 ms 12772 KB Correct
202 Correct 95 ms 13540 KB Correct
203 Correct 157 ms 12800 KB Correct
204 Correct 84 ms 14756 KB Correct
205 Correct 82 ms 13476 KB Correct
206 Correct 221 ms 13788 KB Correct
207 Correct 196 ms 13956 KB Correct
208 Correct 121 ms 13624 KB Correct
209 Correct 101 ms 14220 KB Correct
210 Correct 78 ms 13308 KB Correct
211 Correct 84 ms 13296 KB Correct
212 Correct 90 ms 13976 KB Correct
213 Correct 225 ms 14060 KB Correct
214 Correct 223 ms 13040 KB Correct
215 Correct 83 ms 15004 KB Correct
216 Correct 256 ms 13940 KB Correct
217 Correct 223 ms 14236 KB Correct
218 Correct 72 ms 13036 KB Correct
219 Correct 86 ms 12704 KB Correct
220 Correct 220 ms 13976 KB Correct
221 Correct 196 ms 14016 KB Correct
222 Correct 250 ms 14784 KB Correct
223 Correct 152 ms 15088 KB Correct
224 Correct 199 ms 14600 KB Correct
225 Correct 84 ms 14236 KB Correct
226 Correct 83 ms 13980 KB Correct
227 Correct 207 ms 14060 KB Correct
228 Correct 223 ms 12724 KB Correct
229 Correct 80 ms 13216 KB Correct
230 Correct 81 ms 13940 KB Correct
231 Correct 104 ms 14572 KB Correct
232 Correct 76 ms 12564 KB Correct
233 Correct 79 ms 14500 KB Correct
234 Correct 89 ms 11512 KB Correct
235 Correct 95 ms 11516 KB Correct
236 Correct 53 ms 7336 KB Correct
237 Correct 52 ms 7328 KB Correct
238 Correct 59 ms 7312 KB Correct
239 Correct 40 ms 6748 KB Correct
240 Correct 82 ms 8700 KB Correct
241 Correct 78 ms 8700 KB Correct
242 Correct 77 ms 8696 KB Correct
243 Correct 80 ms 8864 KB Correct
244 Correct 72 ms 8860 KB Correct
245 Correct 79 ms 8440 KB Correct
246 Correct 78 ms 8452 KB Correct
247 Correct 86 ms 8724 KB Correct
248 Correct 80 ms 8696 KB Correct
249 Correct 79 ms 8864 KB Correct
250 Correct 82 ms 8540 KB Correct
251 Correct 80 ms 8712 KB Correct
252 Correct 66 ms 8528 KB Correct
253 Correct 76 ms 8860 KB Correct
254 Correct 80 ms 8704 KB Correct
255 Correct 75 ms 8740 KB Correct
256 Correct 80 ms 8584 KB Correct
257 Correct 78 ms 8688 KB Correct
258 Correct 78 ms 8764 KB Correct
259 Correct 81 ms 8860 KB Correct
260 Correct 74 ms 8544 KB Correct
261 Correct 83 ms 8604 KB Correct
262 Correct 75 ms 8572 KB Correct
263 Correct 83 ms 8688 KB Correct
264 Correct 78 ms 8860 KB Correct
265 Incorrect 60 ms 7336 KB Not correct
266 Halted 0 ms 0 KB -