#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);
| ~~~~~~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
768 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
226 ms |
11680 KB |
Correct |
2 |
Correct |
233 ms |
11824 KB |
Correct |
3 |
Correct |
114 ms |
12500 KB |
Correct |
4 |
Correct |
108 ms |
13056 KB |
Correct |
5 |
Correct |
209 ms |
12736 KB |
Correct |
6 |
Correct |
89 ms |
12828 KB |
Correct |
7 |
Correct |
88 ms |
11424 KB |
Correct |
8 |
Correct |
233 ms |
11924 KB |
Correct |
9 |
Correct |
213 ms |
12352 KB |
Correct |
10 |
Correct |
176 ms |
11932 KB |
Correct |
11 |
Correct |
108 ms |
12700 KB |
Correct |
12 |
Correct |
305 ms |
11880 KB |
Correct |
13 |
Correct |
88 ms |
11504 KB |
Correct |
14 |
Correct |
93 ms |
11792 KB |
Correct |
15 |
Correct |
214 ms |
12404 KB |
Correct |
16 |
Correct |
217 ms |
13468 KB |
Correct |
17 |
Correct |
143 ms |
11048 KB |
Correct |
18 |
Correct |
96 ms |
11424 KB |
Correct |
19 |
Correct |
151 ms |
11124 KB |
Correct |
20 |
Correct |
94 ms |
12612 KB |
Correct |
21 |
Correct |
90 ms |
11844 KB |
Correct |
22 |
Correct |
227 ms |
11904 KB |
Correct |
23 |
Correct |
210 ms |
12108 KB |
Correct |
24 |
Correct |
110 ms |
11420 KB |
Correct |
25 |
Correct |
99 ms |
12448 KB |
Correct |
26 |
Correct |
97 ms |
11164 KB |
Correct |
27 |
Correct |
86 ms |
11844 KB |
Correct |
28 |
Correct |
77 ms |
12116 KB |
Correct |
29 |
Correct |
229 ms |
11984 KB |
Correct |
30 |
Correct |
213 ms |
11260 KB |
Correct |
31 |
Correct |
89 ms |
12956 KB |
Correct |
32 |
Correct |
223 ms |
12204 KB |
Correct |
33 |
Correct |
228 ms |
12304 KB |
Correct |
34 |
Correct |
96 ms |
11540 KB |
Correct |
35 |
Correct |
91 ms |
11092 KB |
Correct |
36 |
Correct |
230 ms |
12192 KB |
Correct |
37 |
Correct |
237 ms |
11996 KB |
Correct |
38 |
Correct |
269 ms |
12744 KB |
Correct |
39 |
Correct |
161 ms |
12900 KB |
Correct |
40 |
Correct |
198 ms |
12704 KB |
Correct |
41 |
Correct |
100 ms |
12420 KB |
Correct |
42 |
Correct |
89 ms |
12128 KB |
Correct |
43 |
Correct |
229 ms |
12452 KB |
Correct |
44 |
Correct |
215 ms |
10960 KB |
Correct |
45 |
Correct |
96 ms |
11292 KB |
Correct |
46 |
Correct |
95 ms |
11616 KB |
Correct |
47 |
Correct |
106 ms |
12448 KB |
Correct |
48 |
Correct |
94 ms |
10920 KB |
Correct |
49 |
Correct |
90 ms |
12448 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
7956 KB |
Correct |
2 |
Correct |
83 ms |
8220 KB |
Correct |
3 |
Correct |
90 ms |
7780 KB |
Correct |
4 |
Correct |
105 ms |
10752 KB |
Correct |
5 |
Correct |
125 ms |
10008 KB |
Correct |
6 |
Correct |
153 ms |
10060 KB |
Correct |
7 |
Correct |
81 ms |
7584 KB |
Correct |
8 |
Correct |
80 ms |
7764 KB |
Correct |
9 |
Correct |
73 ms |
7500 KB |
Correct |
10 |
Correct |
79 ms |
7764 KB |
Correct |
11 |
Correct |
74 ms |
7836 KB |
Correct |
12 |
Correct |
82 ms |
7756 KB |
Correct |
13 |
Correct |
88 ms |
7760 KB |
Correct |
14 |
Correct |
62 ms |
5800 KB |
Correct |
15 |
Correct |
56 ms |
5992 KB |
Correct |
16 |
Correct |
75 ms |
7656 KB |
Correct |
17 |
Correct |
81 ms |
7524 KB |
Correct |
18 |
Correct |
79 ms |
7500 KB |
Correct |
19 |
Correct |
79 ms |
7584 KB |
Correct |
20 |
Correct |
62 ms |
5968 KB |
Correct |
21 |
Correct |
60 ms |
5980 KB |
Correct |
22 |
Correct |
55 ms |
5888 KB |
Correct |
23 |
Correct |
63 ms |
5884 KB |
Correct |
24 |
Correct |
64 ms |
5992 KB |
Correct |
25 |
Correct |
55 ms |
5796 KB |
Correct |
26 |
Correct |
83 ms |
7836 KB |
Correct |
27 |
Correct |
84 ms |
7752 KB |
Correct |
28 |
Correct |
81 ms |
7840 KB |
Correct |
29 |
Correct |
80 ms |
7836 KB |
Correct |
30 |
Correct |
82 ms |
8032 KB |
Correct |
31 |
Correct |
81 ms |
7840 KB |
Correct |
32 |
Correct |
81 ms |
7844 KB |
Correct |
33 |
Correct |
84 ms |
8012 KB |
Correct |
34 |
Correct |
82 ms |
7820 KB |
Correct |
35 |
Correct |
75 ms |
7956 KB |
Correct |
36 |
Correct |
81 ms |
8024 KB |
Correct |
37 |
Correct |
75 ms |
7772 KB |
Correct |
38 |
Correct |
77 ms |
7756 KB |
Correct |
39 |
Correct |
81 ms |
7840 KB |
Correct |
40 |
Correct |
83 ms |
7704 KB |
Correct |
41 |
Correct |
89 ms |
8096 KB |
Correct |
42 |
Correct |
87 ms |
8024 KB |
Correct |
43 |
Correct |
81 ms |
7948 KB |
Correct |
44 |
Correct |
91 ms |
7840 KB |
Correct |
45 |
Correct |
82 ms |
8092 KB |
Correct |
46 |
Correct |
86 ms |
7948 KB |
Correct |
47 |
Correct |
82 ms |
7844 KB |
Correct |
48 |
Correct |
90 ms |
8020 KB |
Correct |
49 |
Correct |
77 ms |
8008 KB |
Correct |
50 |
Correct |
87 ms |
7836 KB |
Correct |
51 |
Correct |
83 ms |
7836 KB |
Correct |
52 |
Correct |
82 ms |
7836 KB |
Correct |
53 |
Correct |
84 ms |
7772 KB |
Correct |
54 |
Correct |
78 ms |
7840 KB |
Correct |
55 |
Correct |
68 ms |
7932 KB |
Correct |
56 |
Runtime error |
87 ms |
11936 KB |
Execution killed with signal 6 |
57 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
768 KB |
Correct |
2 |
Correct |
226 ms |
11680 KB |
Correct |
3 |
Correct |
233 ms |
11824 KB |
Correct |
4 |
Correct |
114 ms |
12500 KB |
Correct |
5 |
Correct |
108 ms |
13056 KB |
Correct |
6 |
Correct |
209 ms |
12736 KB |
Correct |
7 |
Correct |
89 ms |
12828 KB |
Correct |
8 |
Correct |
88 ms |
11424 KB |
Correct |
9 |
Correct |
233 ms |
11924 KB |
Correct |
10 |
Correct |
213 ms |
12352 KB |
Correct |
11 |
Correct |
176 ms |
11932 KB |
Correct |
12 |
Correct |
108 ms |
12700 KB |
Correct |
13 |
Correct |
305 ms |
11880 KB |
Correct |
14 |
Correct |
88 ms |
11504 KB |
Correct |
15 |
Correct |
93 ms |
11792 KB |
Correct |
16 |
Correct |
214 ms |
12404 KB |
Correct |
17 |
Correct |
217 ms |
13468 KB |
Correct |
18 |
Correct |
143 ms |
11048 KB |
Correct |
19 |
Correct |
96 ms |
11424 KB |
Correct |
20 |
Correct |
151 ms |
11124 KB |
Correct |
21 |
Correct |
94 ms |
12612 KB |
Correct |
22 |
Correct |
90 ms |
11844 KB |
Correct |
23 |
Correct |
227 ms |
11904 KB |
Correct |
24 |
Correct |
210 ms |
12108 KB |
Correct |
25 |
Correct |
110 ms |
11420 KB |
Correct |
26 |
Correct |
99 ms |
12448 KB |
Correct |
27 |
Correct |
97 ms |
11164 KB |
Correct |
28 |
Correct |
86 ms |
11844 KB |
Correct |
29 |
Correct |
77 ms |
12116 KB |
Correct |
30 |
Correct |
229 ms |
11984 KB |
Correct |
31 |
Correct |
213 ms |
11260 KB |
Correct |
32 |
Correct |
89 ms |
12956 KB |
Correct |
33 |
Correct |
223 ms |
12204 KB |
Correct |
34 |
Correct |
228 ms |
12304 KB |
Correct |
35 |
Correct |
96 ms |
11540 KB |
Correct |
36 |
Correct |
91 ms |
11092 KB |
Correct |
37 |
Correct |
230 ms |
12192 KB |
Correct |
38 |
Correct |
237 ms |
11996 KB |
Correct |
39 |
Correct |
269 ms |
12744 KB |
Correct |
40 |
Correct |
161 ms |
12900 KB |
Correct |
41 |
Correct |
198 ms |
12704 KB |
Correct |
42 |
Correct |
100 ms |
12420 KB |
Correct |
43 |
Correct |
89 ms |
12128 KB |
Correct |
44 |
Correct |
229 ms |
12452 KB |
Correct |
45 |
Correct |
215 ms |
10960 KB |
Correct |
46 |
Correct |
96 ms |
11292 KB |
Correct |
47 |
Correct |
95 ms |
11616 KB |
Correct |
48 |
Correct |
106 ms |
12448 KB |
Correct |
49 |
Correct |
94 ms |
10920 KB |
Correct |
50 |
Correct |
90 ms |
12448 KB |
Correct |
51 |
Correct |
83 ms |
7956 KB |
Correct |
52 |
Correct |
83 ms |
8220 KB |
Correct |
53 |
Correct |
90 ms |
7780 KB |
Correct |
54 |
Correct |
105 ms |
10752 KB |
Correct |
55 |
Correct |
125 ms |
10008 KB |
Correct |
56 |
Correct |
153 ms |
10060 KB |
Correct |
57 |
Correct |
81 ms |
7584 KB |
Correct |
58 |
Correct |
80 ms |
7764 KB |
Correct |
59 |
Correct |
73 ms |
7500 KB |
Correct |
60 |
Correct |
79 ms |
7764 KB |
Correct |
61 |
Correct |
74 ms |
7836 KB |
Correct |
62 |
Correct |
82 ms |
7756 KB |
Correct |
63 |
Correct |
88 ms |
7760 KB |
Correct |
64 |
Correct |
62 ms |
5800 KB |
Correct |
65 |
Correct |
56 ms |
5992 KB |
Correct |
66 |
Correct |
75 ms |
7656 KB |
Correct |
67 |
Correct |
81 ms |
7524 KB |
Correct |
68 |
Correct |
79 ms |
7500 KB |
Correct |
69 |
Correct |
79 ms |
7584 KB |
Correct |
70 |
Correct |
62 ms |
5968 KB |
Correct |
71 |
Correct |
60 ms |
5980 KB |
Correct |
72 |
Correct |
55 ms |
5888 KB |
Correct |
73 |
Correct |
63 ms |
5884 KB |
Correct |
74 |
Correct |
64 ms |
5992 KB |
Correct |
75 |
Correct |
55 ms |
5796 KB |
Correct |
76 |
Correct |
83 ms |
7836 KB |
Correct |
77 |
Correct |
84 ms |
7752 KB |
Correct |
78 |
Correct |
81 ms |
7840 KB |
Correct |
79 |
Correct |
80 ms |
7836 KB |
Correct |
80 |
Correct |
82 ms |
8032 KB |
Correct |
81 |
Correct |
81 ms |
7840 KB |
Correct |
82 |
Correct |
81 ms |
7844 KB |
Correct |
83 |
Correct |
84 ms |
8012 KB |
Correct |
84 |
Correct |
82 ms |
7820 KB |
Correct |
85 |
Correct |
75 ms |
7956 KB |
Correct |
86 |
Correct |
81 ms |
8024 KB |
Correct |
87 |
Correct |
75 ms |
7772 KB |
Correct |
88 |
Correct |
77 ms |
7756 KB |
Correct |
89 |
Correct |
81 ms |
7840 KB |
Correct |
90 |
Correct |
83 ms |
7704 KB |
Correct |
91 |
Correct |
89 ms |
8096 KB |
Correct |
92 |
Correct |
87 ms |
8024 KB |
Correct |
93 |
Correct |
81 ms |
7948 KB |
Correct |
94 |
Correct |
91 ms |
7840 KB |
Correct |
95 |
Correct |
82 ms |
8092 KB |
Correct |
96 |
Correct |
86 ms |
7948 KB |
Correct |
97 |
Correct |
82 ms |
7844 KB |
Correct |
98 |
Correct |
90 ms |
8020 KB |
Correct |
99 |
Correct |
77 ms |
8008 KB |
Correct |
100 |
Correct |
87 ms |
7836 KB |
Correct |
101 |
Correct |
83 ms |
7836 KB |
Correct |
102 |
Correct |
82 ms |
7836 KB |
Correct |
103 |
Correct |
84 ms |
7772 KB |
Correct |
104 |
Correct |
78 ms |
7840 KB |
Correct |
105 |
Correct |
68 ms |
7932 KB |
Correct |
106 |
Runtime error |
87 ms |
11936 KB |
Execution killed with signal 6 |
107 |
Halted |
0 ms |
0 KB |
- |