#include <vector>
#include "incursion.h"
#include <cstdio>
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
#define sz(x) ((int)(x).size())
using pii = pair<int, int>;
using tii = tuple<int, int, int>;
const int nmax = 45e3 + 5;
vector<int> g[nmax];
int area[nmax];
int father[nmax];
#define N uhasfuhafs
int N;
void initarea(int node, int f) {
area[node] = 1;
father[node] = f;
for(auto x : g[node]) {
if(x == f) continue;
initarea(x, node);
area[node] += area[x];
}
return;
}
pii findcentr(int node, int f) {
for(auto x : g[node]) {
if(x == f) continue;
if(area[x] * 2 == N) { return pii{node, x}; }
if(area[x] * 2 > N) { return findcentr(x, node); }
}
return pii{node, node};
}
int make_graph(vector<pii> F) {
for(auto &[a, b] : F) --a, --b;
N = sz(F) + 1;
for(int i = 0; i <= N + 1; i++) g[i].clear();
for(auto [a, b] : F) {
g[a].emplace_back(b);
g[b].emplace_back(a);
}
int cnt = 0;
for(int i = 0; i < N; i++) {
if(sz(g[i]) == 2) cnt++;
}
if(cnt == 1) {
for(int i = 0; i < N; i++)
if(sz(g[i]) == 2) return i;
}
initarea(0, 0);
auto [u_, v_] = findcentr(0, 0);
int root;
if(u_ != v_) {
for(int i = 0; i < sz(g[u_]); i++) {
if(g[u_][i] == v_) {
swap(g[u_][i], g[u_].back());
g[u_].pop_back();
break;
}
}
for(int i = 0; i < sz(g[v_]); i++) {
if(g[v_][i] == u_) {
swap(g[v_][i], g[v_].back());
g[v_].pop_back();
break;
}
}
g[u_].emplace_back(N);
g[v_].emplace_back(N);
g[N].emplace_back(u_);
g[N].emplace_back(v_);
N++;
root = N - 1;
}
else { root = u_; }
initarea(root, root);
for(auto x : g[root])
assert(area[x] * 2 < N);
return root;
}
vector<int> known;
bool dfs(int node, int f, int where) {
bool znayu = node == where;
for(auto x : g[node]) {
if(x == f) continue;
znayu |= dfs(x, node, where);
}
known[node] = znayu;
return known[node];
}
std::vector<int> mark(std::vector<std::pair<int, int>> F, int safe) {
--safe;
int root = make_graph(F);
known.resize(N);
dfs(root, root, safe);
//cerr << root + 1 << '\n';
known.resize(sz(F) + 1);
return known;
}
int go(int x) {
return visit(x +1);
}
void locate(std::vector<std::pair<int, int>> F, int curr, int t) {
--curr;
int root = make_graph(F);
//for(int i = 0; i< N; i++) {
//cerr << i << ": ";
//for(auto x : g[i]) cerr << x << ' ';
//cerr << '\n';
//}
known.assign(N, -1);
if(N != sz(F) + 1)
known.back() = 1;
initarea(root, root);
while(1) {
if(t == 0) {
int u = father[curr];
if(u == sz(F) + 1) {
curr = g[u][0] ^ g[u][1] ^ curr;
t = go(curr);
}
else {
curr = father[curr];
t = go(curr);
}
}
else {
int a = -1, b = -1;
for(auto x : g[curr]) {
if(x == father[curr]) continue;
if(a == -1) a = x;
else b = x;
}
//cerr << curr << ": " << a << ' ' << b << '\n';
if(a == -1 && b == -1) return;
if(b == -1) {
int h = go(a);
if(h == 1) {
curr = a;
t = 1;
continue;
}
go(curr);
return;
}
else {
if(area[a] < area[b]) swap(a, b);
int h = go(a);
if(h == 1) {
curr = a;
t = 1;
continue;
}
go(curr);
h = go(b);
if(h == 1) {
curr = b;
t = 1;
continue;
}
go(curr);
return;
}
}
}
}
#undef N
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 |
1 ms |
2824 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
225 ms |
12804 KB |
Correct |
2 |
Correct |
237 ms |
13184 KB |
Correct |
3 |
Correct |
127 ms |
13856 KB |
Correct |
4 |
Correct |
102 ms |
14764 KB |
Correct |
5 |
Correct |
203 ms |
14372 KB |
Correct |
6 |
Correct |
90 ms |
14712 KB |
Correct |
7 |
Correct |
87 ms |
12960 KB |
Correct |
8 |
Correct |
216 ms |
13336 KB |
Correct |
9 |
Correct |
218 ms |
13860 KB |
Correct |
10 |
Correct |
183 ms |
13200 KB |
Correct |
11 |
Correct |
109 ms |
14664 KB |
Correct |
12 |
Correct |
252 ms |
13380 KB |
Correct |
13 |
Correct |
89 ms |
12864 KB |
Correct |
14 |
Correct |
87 ms |
13352 KB |
Correct |
15 |
Correct |
202 ms |
13960 KB |
Correct |
16 |
Correct |
218 ms |
15124 KB |
Correct |
17 |
Correct |
136 ms |
12172 KB |
Correct |
18 |
Correct |
102 ms |
12940 KB |
Correct |
19 |
Correct |
156 ms |
12188 KB |
Correct |
20 |
Correct |
84 ms |
14464 KB |
Correct |
21 |
Correct |
82 ms |
13212 KB |
Correct |
22 |
Correct |
210 ms |
13212 KB |
Correct |
23 |
Correct |
221 ms |
13448 KB |
Correct |
24 |
Correct |
108 ms |
13016 KB |
Correct |
25 |
Correct |
95 ms |
13940 KB |
Correct |
26 |
Correct |
95 ms |
12824 KB |
Correct |
27 |
Correct |
90 ms |
13240 KB |
Correct |
28 |
Correct |
79 ms |
13700 KB |
Correct |
29 |
Correct |
219 ms |
13756 KB |
Correct |
30 |
Correct |
242 ms |
12572 KB |
Correct |
31 |
Correct |
90 ms |
14460 KB |
Correct |
32 |
Correct |
244 ms |
13628 KB |
Correct |
33 |
Correct |
238 ms |
13780 KB |
Correct |
34 |
Correct |
88 ms |
12676 KB |
Correct |
35 |
Correct |
87 ms |
12424 KB |
Correct |
36 |
Correct |
219 ms |
13556 KB |
Correct |
37 |
Correct |
211 ms |
13636 KB |
Correct |
38 |
Correct |
281 ms |
14396 KB |
Correct |
39 |
Correct |
154 ms |
14784 KB |
Correct |
40 |
Correct |
227 ms |
14016 KB |
Correct |
41 |
Correct |
90 ms |
14232 KB |
Correct |
42 |
Correct |
87 ms |
13780 KB |
Correct |
43 |
Correct |
224 ms |
13632 KB |
Correct |
44 |
Correct |
212 ms |
12192 KB |
Correct |
45 |
Correct |
95 ms |
13096 KB |
Correct |
46 |
Correct |
86 ms |
13116 KB |
Correct |
47 |
Correct |
100 ms |
13888 KB |
Correct |
48 |
Correct |
77 ms |
12448 KB |
Correct |
49 |
Correct |
84 ms |
14220 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
8040 KB |
Correct |
2 |
Correct |
84 ms |
8016 KB |
Correct |
3 |
Correct |
79 ms |
7996 KB |
Correct |
4 |
Correct |
82 ms |
10484 KB |
Correct |
5 |
Correct |
133 ms |
10472 KB |
Correct |
6 |
Correct |
154 ms |
10656 KB |
Correct |
7 |
Correct |
74 ms |
7780 KB |
Correct |
8 |
Correct |
77 ms |
7980 KB |
Correct |
9 |
Correct |
71 ms |
7932 KB |
Correct |
10 |
Correct |
73 ms |
7660 KB |
Correct |
11 |
Correct |
69 ms |
7928 KB |
Correct |
12 |
Correct |
77 ms |
7868 KB |
Correct |
13 |
Correct |
79 ms |
7664 KB |
Correct |
14 |
Correct |
54 ms |
6452 KB |
Correct |
15 |
Correct |
56 ms |
6456 KB |
Correct |
16 |
Correct |
73 ms |
7660 KB |
Correct |
17 |
Correct |
76 ms |
7872 KB |
Correct |
18 |
Correct |
72 ms |
7704 KB |
Correct |
19 |
Correct |
72 ms |
7700 KB |
Correct |
20 |
Correct |
51 ms |
6708 KB |
Correct |
21 |
Correct |
53 ms |
6768 KB |
Correct |
22 |
Correct |
57 ms |
6448 KB |
Correct |
23 |
Correct |
60 ms |
6832 KB |
Correct |
24 |
Correct |
47 ms |
6584 KB |
Correct |
25 |
Correct |
57 ms |
6444 KB |
Correct |
26 |
Correct |
79 ms |
7976 KB |
Correct |
27 |
Correct |
76 ms |
8000 KB |
Correct |
28 |
Correct |
71 ms |
8008 KB |
Correct |
29 |
Correct |
82 ms |
7812 KB |
Correct |
30 |
Correct |
83 ms |
7976 KB |
Correct |
31 |
Correct |
82 ms |
7868 KB |
Correct |
32 |
Correct |
79 ms |
8000 KB |
Correct |
33 |
Correct |
70 ms |
7972 KB |
Correct |
34 |
Correct |
75 ms |
7964 KB |
Correct |
35 |
Correct |
80 ms |
7868 KB |
Correct |
36 |
Correct |
70 ms |
7944 KB |
Correct |
37 |
Correct |
83 ms |
7868 KB |
Correct |
38 |
Correct |
76 ms |
7920 KB |
Correct |
39 |
Correct |
72 ms |
7824 KB |
Correct |
40 |
Correct |
76 ms |
7972 KB |
Correct |
41 |
Correct |
78 ms |
7872 KB |
Correct |
42 |
Correct |
86 ms |
7776 KB |
Correct |
43 |
Correct |
79 ms |
7988 KB |
Correct |
44 |
Correct |
82 ms |
7868 KB |
Correct |
45 |
Correct |
72 ms |
7948 KB |
Correct |
46 |
Correct |
81 ms |
7860 KB |
Correct |
47 |
Correct |
71 ms |
7968 KB |
Correct |
48 |
Correct |
76 ms |
7996 KB |
Correct |
49 |
Correct |
80 ms |
7808 KB |
Correct |
50 |
Correct |
70 ms |
7928 KB |
Correct |
51 |
Correct |
81 ms |
7876 KB |
Correct |
52 |
Correct |
79 ms |
7988 KB |
Correct |
53 |
Correct |
76 ms |
7876 KB |
Correct |
54 |
Correct |
76 ms |
7972 KB |
Correct |
55 |
Correct |
78 ms |
7976 KB |
Correct |
56 |
Correct |
77 ms |
7964 KB |
Correct |
57 |
Correct |
63 ms |
7916 KB |
Correct |
58 |
Correct |
81 ms |
7876 KB |
Correct |
59 |
Correct |
73 ms |
7976 KB |
Correct |
60 |
Correct |
74 ms |
7920 KB |
Correct |
61 |
Correct |
73 ms |
7892 KB |
Correct |
62 |
Correct |
76 ms |
8000 KB |
Correct |
63 |
Correct |
75 ms |
7928 KB |
Correct |
64 |
Correct |
70 ms |
7884 KB |
Correct |
65 |
Correct |
71 ms |
8140 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2824 KB |
Correct |
2 |
Correct |
225 ms |
12804 KB |
Correct |
3 |
Correct |
237 ms |
13184 KB |
Correct |
4 |
Correct |
127 ms |
13856 KB |
Correct |
5 |
Correct |
102 ms |
14764 KB |
Correct |
6 |
Correct |
203 ms |
14372 KB |
Correct |
7 |
Correct |
90 ms |
14712 KB |
Correct |
8 |
Correct |
87 ms |
12960 KB |
Correct |
9 |
Correct |
216 ms |
13336 KB |
Correct |
10 |
Correct |
218 ms |
13860 KB |
Correct |
11 |
Correct |
183 ms |
13200 KB |
Correct |
12 |
Correct |
109 ms |
14664 KB |
Correct |
13 |
Correct |
252 ms |
13380 KB |
Correct |
14 |
Correct |
89 ms |
12864 KB |
Correct |
15 |
Correct |
87 ms |
13352 KB |
Correct |
16 |
Correct |
202 ms |
13960 KB |
Correct |
17 |
Correct |
218 ms |
15124 KB |
Correct |
18 |
Correct |
136 ms |
12172 KB |
Correct |
19 |
Correct |
102 ms |
12940 KB |
Correct |
20 |
Correct |
156 ms |
12188 KB |
Correct |
21 |
Correct |
84 ms |
14464 KB |
Correct |
22 |
Correct |
82 ms |
13212 KB |
Correct |
23 |
Correct |
210 ms |
13212 KB |
Correct |
24 |
Correct |
221 ms |
13448 KB |
Correct |
25 |
Correct |
108 ms |
13016 KB |
Correct |
26 |
Correct |
95 ms |
13940 KB |
Correct |
27 |
Correct |
95 ms |
12824 KB |
Correct |
28 |
Correct |
90 ms |
13240 KB |
Correct |
29 |
Correct |
79 ms |
13700 KB |
Correct |
30 |
Correct |
219 ms |
13756 KB |
Correct |
31 |
Correct |
242 ms |
12572 KB |
Correct |
32 |
Correct |
90 ms |
14460 KB |
Correct |
33 |
Correct |
244 ms |
13628 KB |
Correct |
34 |
Correct |
238 ms |
13780 KB |
Correct |
35 |
Correct |
88 ms |
12676 KB |
Correct |
36 |
Correct |
87 ms |
12424 KB |
Correct |
37 |
Correct |
219 ms |
13556 KB |
Correct |
38 |
Correct |
211 ms |
13636 KB |
Correct |
39 |
Correct |
281 ms |
14396 KB |
Correct |
40 |
Correct |
154 ms |
14784 KB |
Correct |
41 |
Correct |
227 ms |
14016 KB |
Correct |
42 |
Correct |
90 ms |
14232 KB |
Correct |
43 |
Correct |
87 ms |
13780 KB |
Correct |
44 |
Correct |
224 ms |
13632 KB |
Correct |
45 |
Correct |
212 ms |
12192 KB |
Correct |
46 |
Correct |
95 ms |
13096 KB |
Correct |
47 |
Correct |
86 ms |
13116 KB |
Correct |
48 |
Correct |
100 ms |
13888 KB |
Correct |
49 |
Correct |
77 ms |
12448 KB |
Correct |
50 |
Correct |
84 ms |
14220 KB |
Correct |
51 |
Correct |
75 ms |
8040 KB |
Correct |
52 |
Correct |
84 ms |
8016 KB |
Correct |
53 |
Correct |
79 ms |
7996 KB |
Correct |
54 |
Correct |
82 ms |
10484 KB |
Correct |
55 |
Correct |
133 ms |
10472 KB |
Correct |
56 |
Correct |
154 ms |
10656 KB |
Correct |
57 |
Correct |
74 ms |
7780 KB |
Correct |
58 |
Correct |
77 ms |
7980 KB |
Correct |
59 |
Correct |
71 ms |
7932 KB |
Correct |
60 |
Correct |
73 ms |
7660 KB |
Correct |
61 |
Correct |
69 ms |
7928 KB |
Correct |
62 |
Correct |
77 ms |
7868 KB |
Correct |
63 |
Correct |
79 ms |
7664 KB |
Correct |
64 |
Correct |
54 ms |
6452 KB |
Correct |
65 |
Correct |
56 ms |
6456 KB |
Correct |
66 |
Correct |
73 ms |
7660 KB |
Correct |
67 |
Correct |
76 ms |
7872 KB |
Correct |
68 |
Correct |
72 ms |
7704 KB |
Correct |
69 |
Correct |
72 ms |
7700 KB |
Correct |
70 |
Correct |
51 ms |
6708 KB |
Correct |
71 |
Correct |
53 ms |
6768 KB |
Correct |
72 |
Correct |
57 ms |
6448 KB |
Correct |
73 |
Correct |
60 ms |
6832 KB |
Correct |
74 |
Correct |
47 ms |
6584 KB |
Correct |
75 |
Correct |
57 ms |
6444 KB |
Correct |
76 |
Correct |
79 ms |
7976 KB |
Correct |
77 |
Correct |
76 ms |
8000 KB |
Correct |
78 |
Correct |
71 ms |
8008 KB |
Correct |
79 |
Correct |
82 ms |
7812 KB |
Correct |
80 |
Correct |
83 ms |
7976 KB |
Correct |
81 |
Correct |
82 ms |
7868 KB |
Correct |
82 |
Correct |
79 ms |
8000 KB |
Correct |
83 |
Correct |
70 ms |
7972 KB |
Correct |
84 |
Correct |
75 ms |
7964 KB |
Correct |
85 |
Correct |
80 ms |
7868 KB |
Correct |
86 |
Correct |
70 ms |
7944 KB |
Correct |
87 |
Correct |
83 ms |
7868 KB |
Correct |
88 |
Correct |
76 ms |
7920 KB |
Correct |
89 |
Correct |
72 ms |
7824 KB |
Correct |
90 |
Correct |
76 ms |
7972 KB |
Correct |
91 |
Correct |
78 ms |
7872 KB |
Correct |
92 |
Correct |
86 ms |
7776 KB |
Correct |
93 |
Correct |
79 ms |
7988 KB |
Correct |
94 |
Correct |
82 ms |
7868 KB |
Correct |
95 |
Correct |
72 ms |
7948 KB |
Correct |
96 |
Correct |
81 ms |
7860 KB |
Correct |
97 |
Correct |
71 ms |
7968 KB |
Correct |
98 |
Correct |
76 ms |
7996 KB |
Correct |
99 |
Correct |
80 ms |
7808 KB |
Correct |
100 |
Correct |
70 ms |
7928 KB |
Correct |
101 |
Correct |
81 ms |
7876 KB |
Correct |
102 |
Correct |
79 ms |
7988 KB |
Correct |
103 |
Correct |
76 ms |
7876 KB |
Correct |
104 |
Correct |
76 ms |
7972 KB |
Correct |
105 |
Correct |
78 ms |
7976 KB |
Correct |
106 |
Correct |
77 ms |
7964 KB |
Correct |
107 |
Correct |
63 ms |
7916 KB |
Correct |
108 |
Correct |
81 ms |
7876 KB |
Correct |
109 |
Correct |
73 ms |
7976 KB |
Correct |
110 |
Correct |
74 ms |
7920 KB |
Correct |
111 |
Correct |
73 ms |
7892 KB |
Correct |
112 |
Correct |
76 ms |
8000 KB |
Correct |
113 |
Correct |
75 ms |
7928 KB |
Correct |
114 |
Correct |
70 ms |
7884 KB |
Correct |
115 |
Correct |
71 ms |
8140 KB |
Correct |
116 |
Correct |
95 ms |
8648 KB |
Correct |
117 |
Incorrect |
88 ms |
8488 KB |
Not correct |
118 |
Halted |
0 ms |
0 KB |
- |