#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) {
//cerr << node << ' ' << area[node] << '\n';
for(auto x : g[node]) {
if(x == f) continue;
//cerr << '\t' << x << ' ' << area[x] << '\n';
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);
}
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_; }
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 |
2 ms |
2820 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
225 ms |
12840 KB |
Correct |
2 |
Correct |
219 ms |
13288 KB |
Correct |
3 |
Correct |
105 ms |
13980 KB |
Correct |
4 |
Correct |
117 ms |
14732 KB |
Correct |
5 |
Correct |
203 ms |
14340 KB |
Correct |
6 |
Correct |
87 ms |
14492 KB |
Correct |
7 |
Correct |
80 ms |
13204 KB |
Correct |
8 |
Correct |
228 ms |
13292 KB |
Correct |
9 |
Correct |
219 ms |
13844 KB |
Correct |
10 |
Correct |
163 ms |
13148 KB |
Correct |
11 |
Correct |
102 ms |
14868 KB |
Correct |
12 |
Correct |
263 ms |
13372 KB |
Correct |
13 |
Correct |
80 ms |
12708 KB |
Correct |
14 |
Correct |
65 ms |
13296 KB |
Correct |
15 |
Correct |
214 ms |
13944 KB |
Correct |
16 |
Correct |
196 ms |
15372 KB |
Correct |
17 |
Correct |
139 ms |
12312 KB |
Correct |
18 |
Correct |
90 ms |
12956 KB |
Correct |
19 |
Correct |
161 ms |
12220 KB |
Correct |
20 |
Correct |
93 ms |
14400 KB |
Correct |
21 |
Correct |
97 ms |
13192 KB |
Correct |
22 |
Correct |
220 ms |
13332 KB |
Correct |
23 |
Correct |
222 ms |
13668 KB |
Correct |
24 |
Correct |
105 ms |
13136 KB |
Correct |
25 |
Correct |
92 ms |
13952 KB |
Correct |
26 |
Correct |
90 ms |
12748 KB |
Correct |
27 |
Correct |
88 ms |
13080 KB |
Correct |
28 |
Correct |
89 ms |
13724 KB |
Correct |
29 |
Correct |
233 ms |
13628 KB |
Correct |
30 |
Correct |
218 ms |
12604 KB |
Correct |
31 |
Correct |
93 ms |
14472 KB |
Correct |
32 |
Correct |
242 ms |
13456 KB |
Correct |
33 |
Correct |
248 ms |
13888 KB |
Correct |
34 |
Correct |
83 ms |
12660 KB |
Correct |
35 |
Correct |
78 ms |
12420 KB |
Correct |
36 |
Correct |
218 ms |
13536 KB |
Correct |
37 |
Correct |
223 ms |
13628 KB |
Correct |
38 |
Correct |
248 ms |
14360 KB |
Correct |
39 |
Correct |
152 ms |
14624 KB |
Correct |
40 |
Correct |
210 ms |
14124 KB |
Correct |
41 |
Correct |
86 ms |
13944 KB |
Correct |
42 |
Correct |
86 ms |
13844 KB |
Correct |
43 |
Correct |
225 ms |
13640 KB |
Correct |
44 |
Correct |
207 ms |
12352 KB |
Correct |
45 |
Correct |
91 ms |
12912 KB |
Correct |
46 |
Correct |
81 ms |
13212 KB |
Correct |
47 |
Correct |
101 ms |
13840 KB |
Correct |
48 |
Correct |
84 ms |
12424 KB |
Correct |
49 |
Correct |
83 ms |
14212 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
8472 KB |
Correct |
2 |
Correct |
81 ms |
8332 KB |
Correct |
3 |
Correct |
80 ms |
8356 KB |
Correct |
4 |
Correct |
92 ms |
11820 KB |
Correct |
5 |
Incorrect |
91 ms |
10872 KB |
Not correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2820 KB |
Correct |
2 |
Correct |
225 ms |
12840 KB |
Correct |
3 |
Correct |
219 ms |
13288 KB |
Correct |
4 |
Correct |
105 ms |
13980 KB |
Correct |
5 |
Correct |
117 ms |
14732 KB |
Correct |
6 |
Correct |
203 ms |
14340 KB |
Correct |
7 |
Correct |
87 ms |
14492 KB |
Correct |
8 |
Correct |
80 ms |
13204 KB |
Correct |
9 |
Correct |
228 ms |
13292 KB |
Correct |
10 |
Correct |
219 ms |
13844 KB |
Correct |
11 |
Correct |
163 ms |
13148 KB |
Correct |
12 |
Correct |
102 ms |
14868 KB |
Correct |
13 |
Correct |
263 ms |
13372 KB |
Correct |
14 |
Correct |
80 ms |
12708 KB |
Correct |
15 |
Correct |
65 ms |
13296 KB |
Correct |
16 |
Correct |
214 ms |
13944 KB |
Correct |
17 |
Correct |
196 ms |
15372 KB |
Correct |
18 |
Correct |
139 ms |
12312 KB |
Correct |
19 |
Correct |
90 ms |
12956 KB |
Correct |
20 |
Correct |
161 ms |
12220 KB |
Correct |
21 |
Correct |
93 ms |
14400 KB |
Correct |
22 |
Correct |
97 ms |
13192 KB |
Correct |
23 |
Correct |
220 ms |
13332 KB |
Correct |
24 |
Correct |
222 ms |
13668 KB |
Correct |
25 |
Correct |
105 ms |
13136 KB |
Correct |
26 |
Correct |
92 ms |
13952 KB |
Correct |
27 |
Correct |
90 ms |
12748 KB |
Correct |
28 |
Correct |
88 ms |
13080 KB |
Correct |
29 |
Correct |
89 ms |
13724 KB |
Correct |
30 |
Correct |
233 ms |
13628 KB |
Correct |
31 |
Correct |
218 ms |
12604 KB |
Correct |
32 |
Correct |
93 ms |
14472 KB |
Correct |
33 |
Correct |
242 ms |
13456 KB |
Correct |
34 |
Correct |
248 ms |
13888 KB |
Correct |
35 |
Correct |
83 ms |
12660 KB |
Correct |
36 |
Correct |
78 ms |
12420 KB |
Correct |
37 |
Correct |
218 ms |
13536 KB |
Correct |
38 |
Correct |
223 ms |
13628 KB |
Correct |
39 |
Correct |
248 ms |
14360 KB |
Correct |
40 |
Correct |
152 ms |
14624 KB |
Correct |
41 |
Correct |
210 ms |
14124 KB |
Correct |
42 |
Correct |
86 ms |
13944 KB |
Correct |
43 |
Correct |
86 ms |
13844 KB |
Correct |
44 |
Correct |
225 ms |
13640 KB |
Correct |
45 |
Correct |
207 ms |
12352 KB |
Correct |
46 |
Correct |
91 ms |
12912 KB |
Correct |
47 |
Correct |
81 ms |
13212 KB |
Correct |
48 |
Correct |
101 ms |
13840 KB |
Correct |
49 |
Correct |
84 ms |
12424 KB |
Correct |
50 |
Correct |
83 ms |
14212 KB |
Correct |
51 |
Correct |
86 ms |
8472 KB |
Correct |
52 |
Correct |
81 ms |
8332 KB |
Correct |
53 |
Correct |
80 ms |
8356 KB |
Correct |
54 |
Correct |
92 ms |
11820 KB |
Correct |
55 |
Incorrect |
91 ms |
10872 KB |
Not correct |
56 |
Halted |
0 ms |
0 KB |
- |