#include <bits/stdc++.h>
#include "incursion.h"
#define f0r(i,n) for(int i = 0;i<n;i++)
#define vi vector<int>
using namespace std;
std::vector<int> mark(std::vector<std::pair<int, int>> F, int safe) {
safe--;
int n;
int two;
n = F.size() + 1;
vector<int>dist(n);
dist[safe] = 0;
vector<int>adj[n];
vi deg(n, 0);
vi degcnt(4, 0);
f0r(i, n-1){
adj[--F[i].first].push_back(--F[i].second);
adj[F[i].second].push_back(F[i].first);
deg[F[i].first]++;
deg[F[i].second]++;
}
//f0r(i,n)cout<<deg[i]<<' ';
//cout<<'\n';
f0r(i,n){
if(deg[i] == 2)two = i;
degcnt[deg[i]]++;
}
if(degcnt[3] == 0){
vi col(n, 0);
queue<int>q;
q.push(safe);
vector<bool>vis(n,0);
vis[safe] = 1;
col[safe] = 0;
while(!q.empty()){
int cur = q.front();
q.pop();
for(auto u : adj[cur]){
if(vis[u])continue;
vis[u] = 1;
dist[u] = dist[cur] + 1;
col[u] = (col[cur] + 1) % 3;
q.push(u);
}
}
return col;
}
else{
vi col(n,0);
vi par(n);
par[two] = -1;
queue<int>q;
q.push(two);
while(!q.empty()){
int cur = q.front();
q.pop();
for(auto u : adj[cur]){
if(u != par[cur]){
par[u] = cur;
q.push(u);
}
}
}
//f0r(i,n)cout<<par[i]<<' ';
//cout<<'\n';
int now = safe;
while(now != -1){
//cout<<now<<'\n';
col[now] = 1;
now = par[now];
}
//cout<<cur<<'\n';
//cout<<par[cur]<<'\n';
//cout<<par[par[par[cur]]]<<'\n';
return col;
}
}
void locate(std::vector<std::pair<int, int>> F, int curr, int t) {
int x;
vector<int>nxt = {2, 0, 1};
int n = F.size() + 1;
vector<bool>vis(n+1, 0);
vector<int>adj[n+1];
vi deg(n+1);
vi degcnt(4, 0);
f0r(i, n-1){
adj[F[i].first].push_back(F[i].second);
adj[F[i].second].push_back(F[i].first);
deg[F[i].first]++;
deg[F[i].second]++;
}
int two;
for(int i = 1; i<=n; i++){
if(deg[i]==2)two = i;
degcnt[deg[i]]++;
}
if(degcnt[3] == 0){
vis[curr] = 1;
//queue<int>q;
//q.push(curr);
bool found = false;
int col = t;
int cur = curr;
vi cols(n+1, -1);
cols[curr] = t;
while(!found){
bool ok = 0;
for(auto u : adj[cur]){
if(vis[u])continue;
vis[u] = 1;
x = visit(u);
cols[u] = x;
if(x == nxt[cols[cur]]){
cur = u;
ok = 1;
break;
}
else{
visit(cur);
}
}
if(!ok)return;
}
}
else{
vi par(n+1);
par[two] = -1;
vi d(n+1, 0);
queue<int>q;
q.push(two);
while(!q.empty()){
int cur = q.front();
q.pop();
for(auto u : adj[cur]){
if(u != par[cur]){
par[u] = cur;
d[u] = d[cur] + 1;
q.push(u);
}
}
}
//for(int i = 1; i<=n; i++)cout<<d[i]<<' ';
//cout<<'\n';
vector<bool>viss(n+1, 0);
vi sts(n+1, 0);
priority_queue<pair<int,int>>pq;
for(int i=1; i<=n;i++){
if(deg[i] == 1){
pq.push({d[i], i});
sts[i] = 1;
viss[i] = 1;
}
}
while(!pq.empty()){
int cur = pq.top().second;
pq.pop();
//cout<<cur<<'\n';
//if(par[cur] != -1)sts[par[cur]] += sts[cur];
if(par[cur] != -1 && !viss[par[cur]]){
viss[par[cur]] = 1;
for(auto u : adj[par[cur]]){
if(u != par[par[cur]]){
sts[par[cur]] += sts[u];
}
}
pq.push({d[par[cur]], par[cur]});
}
}
//for(int i = 1; i<=n; i++)cout<<sts[i]<<' ';
//cout<<'\n';
vi vis(n+1, 0);
int cur = curr;
int col = t;
int x;
vis[cur] = 1;
while(col == 0){
cur = par[cur];
vis[cur] = 1;
x = visit(cur);
col = x;
}
bool found = 0;
while(!found){
vector<pair<int,int>>thing;
for(auto u : adj[cur]){
if(!vis[u] && u != par[cur])thing.push_back({sts[u], u});
}
sort(thing.rbegin(), thing.rend());
bool ok =0;
for(auto u : thing){
x = visit(u.second);
if(x == 0){
visit(cur);
}
else{
cur = u.second;
vis[cur] = 1;
col = x;
ok = 1;
break;
}
}
if(!ok)return;
}
}
}
Compilation message
incursion.cpp: In function 'void locate(std::vector<std::pair<int, int> >, int, int)':
incursion.cpp:114:13: warning: unused variable 'col' [-Wunused-variable]
114 | int col = t;
| ^~~
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 |
Partially correct |
0 ms |
768 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
215 ms |
8080 KB |
Partially correct |
2 |
Partially correct |
208 ms |
8068 KB |
Partially correct |
3 |
Partially correct |
97 ms |
7952 KB |
Partially correct |
4 |
Partially correct |
101 ms |
7836 KB |
Partially correct |
5 |
Partially correct |
192 ms |
8080 KB |
Partially correct |
6 |
Partially correct |
84 ms |
7760 KB |
Partially correct |
7 |
Partially correct |
76 ms |
7756 KB |
Partially correct |
8 |
Partially correct |
192 ms |
8276 KB |
Partially correct |
9 |
Partially correct |
220 ms |
8124 KB |
Partially correct |
10 |
Partially correct |
157 ms |
8036 KB |
Partially correct |
11 |
Partially correct |
102 ms |
8136 KB |
Partially correct |
12 |
Partially correct |
276 ms |
7864 KB |
Partially correct |
13 |
Partially correct |
74 ms |
7840 KB |
Partially correct |
14 |
Partially correct |
78 ms |
8292 KB |
Partially correct |
15 |
Partially correct |
221 ms |
8056 KB |
Partially correct |
16 |
Partially correct |
229 ms |
8060 KB |
Partially correct |
17 |
Partially correct |
114 ms |
7844 KB |
Partially correct |
18 |
Partially correct |
89 ms |
7868 KB |
Partially correct |
19 |
Partially correct |
138 ms |
8120 KB |
Partially correct |
20 |
Partially correct |
73 ms |
7772 KB |
Partially correct |
21 |
Partially correct |
78 ms |
7836 KB |
Partially correct |
22 |
Partially correct |
207 ms |
8092 KB |
Partially correct |
23 |
Partially correct |
208 ms |
8068 KB |
Partially correct |
24 |
Partially correct |
90 ms |
8104 KB |
Partially correct |
25 |
Partially correct |
86 ms |
7960 KB |
Partially correct |
26 |
Partially correct |
90 ms |
8124 KB |
Partially correct |
27 |
Partially correct |
79 ms |
7776 KB |
Partially correct |
28 |
Partially correct |
79 ms |
7872 KB |
Partially correct |
29 |
Partially correct |
216 ms |
7872 KB |
Partially correct |
30 |
Partially correct |
199 ms |
8036 KB |
Partially correct |
31 |
Partially correct |
83 ms |
7952 KB |
Partially correct |
32 |
Partially correct |
241 ms |
8132 KB |
Partially correct |
33 |
Partially correct |
230 ms |
8284 KB |
Partially correct |
34 |
Partially correct |
83 ms |
8052 KB |
Partially correct |
35 |
Partially correct |
82 ms |
8276 KB |
Partially correct |
36 |
Partially correct |
189 ms |
7868 KB |
Partially correct |
37 |
Partially correct |
204 ms |
8060 KB |
Partially correct |
38 |
Partially correct |
239 ms |
7868 KB |
Partially correct |
39 |
Partially correct |
145 ms |
8064 KB |
Partially correct |
40 |
Partially correct |
202 ms |
8092 KB |
Partially correct |
41 |
Partially correct |
84 ms |
8036 KB |
Partially correct |
42 |
Partially correct |
81 ms |
8032 KB |
Partially correct |
43 |
Partially correct |
222 ms |
8064 KB |
Partially correct |
44 |
Partially correct |
193 ms |
7872 KB |
Partially correct |
45 |
Partially correct |
84 ms |
7848 KB |
Partially correct |
46 |
Partially correct |
71 ms |
7840 KB |
Partially correct |
47 |
Partially correct |
90 ms |
8268 KB |
Partially correct |
48 |
Partially correct |
73 ms |
7772 KB |
Partially correct |
49 |
Partially correct |
76 ms |
8100 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
8936 KB |
Correct |
2 |
Correct |
82 ms |
8860 KB |
Correct |
3 |
Correct |
83 ms |
8932 KB |
Correct |
4 |
Correct |
96 ms |
8804 KB |
Correct |
5 |
Correct |
156 ms |
8964 KB |
Correct |
6 |
Correct |
164 ms |
8908 KB |
Correct |
7 |
Correct |
94 ms |
8824 KB |
Correct |
8 |
Correct |
81 ms |
8668 KB |
Correct |
9 |
Correct |
84 ms |
8712 KB |
Correct |
10 |
Correct |
77 ms |
8756 KB |
Correct |
11 |
Correct |
79 ms |
8680 KB |
Correct |
12 |
Correct |
72 ms |
8792 KB |
Correct |
13 |
Correct |
74 ms |
8764 KB |
Correct |
14 |
Correct |
65 ms |
6628 KB |
Correct |
15 |
Correct |
59 ms |
6644 KB |
Correct |
16 |
Correct |
80 ms |
8784 KB |
Correct |
17 |
Correct |
75 ms |
8964 KB |
Correct |
18 |
Correct |
89 ms |
8676 KB |
Correct |
19 |
Correct |
81 ms |
8720 KB |
Correct |
20 |
Correct |
61 ms |
6552 KB |
Correct |
21 |
Correct |
56 ms |
6780 KB |
Correct |
22 |
Correct |
62 ms |
6720 KB |
Correct |
23 |
Correct |
60 ms |
6664 KB |
Correct |
24 |
Correct |
61 ms |
6576 KB |
Correct |
25 |
Correct |
55 ms |
6728 KB |
Correct |
26 |
Correct |
80 ms |
8684 KB |
Correct |
27 |
Correct |
80 ms |
8708 KB |
Correct |
28 |
Correct |
86 ms |
8956 KB |
Correct |
29 |
Correct |
82 ms |
8832 KB |
Correct |
30 |
Correct |
92 ms |
8988 KB |
Correct |
31 |
Correct |
86 ms |
9016 KB |
Correct |
32 |
Correct |
89 ms |
8680 KB |
Correct |
33 |
Correct |
80 ms |
8896 KB |
Correct |
34 |
Correct |
82 ms |
8968 KB |
Correct |
35 |
Correct |
83 ms |
8764 KB |
Correct |
36 |
Correct |
84 ms |
9024 KB |
Correct |
37 |
Correct |
92 ms |
8760 KB |
Correct |
38 |
Correct |
82 ms |
8948 KB |
Correct |
39 |
Correct |
95 ms |
8952 KB |
Correct |
40 |
Correct |
83 ms |
8764 KB |
Correct |
41 |
Correct |
88 ms |
8880 KB |
Correct |
42 |
Correct |
81 ms |
8696 KB |
Correct |
43 |
Correct |
82 ms |
8860 KB |
Correct |
44 |
Correct |
82 ms |
8880 KB |
Correct |
45 |
Correct |
89 ms |
8824 KB |
Correct |
46 |
Correct |
82 ms |
8940 KB |
Correct |
47 |
Correct |
93 ms |
8948 KB |
Correct |
48 |
Correct |
81 ms |
8768 KB |
Correct |
49 |
Correct |
70 ms |
8712 KB |
Correct |
50 |
Correct |
84 ms |
8952 KB |
Correct |
51 |
Correct |
94 ms |
8936 KB |
Correct |
52 |
Correct |
92 ms |
8764 KB |
Correct |
53 |
Correct |
75 ms |
8872 KB |
Correct |
54 |
Correct |
63 ms |
8868 KB |
Correct |
55 |
Correct |
78 ms |
9044 KB |
Correct |
56 |
Correct |
86 ms |
8924 KB |
Correct |
57 |
Correct |
74 ms |
8572 KB |
Correct |
58 |
Correct |
81 ms |
8740 KB |
Correct |
59 |
Correct |
80 ms |
8684 KB |
Correct |
60 |
Correct |
92 ms |
8732 KB |
Correct |
61 |
Correct |
77 ms |
8736 KB |
Correct |
62 |
Correct |
89 ms |
8736 KB |
Correct |
63 |
Correct |
82 ms |
8740 KB |
Correct |
64 |
Correct |
84 ms |
8660 KB |
Correct |
65 |
Correct |
96 ms |
8596 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
768 KB |
Partially correct |
2 |
Partially correct |
215 ms |
8080 KB |
Partially correct |
3 |
Partially correct |
208 ms |
8068 KB |
Partially correct |
4 |
Partially correct |
97 ms |
7952 KB |
Partially correct |
5 |
Partially correct |
101 ms |
7836 KB |
Partially correct |
6 |
Partially correct |
192 ms |
8080 KB |
Partially correct |
7 |
Partially correct |
84 ms |
7760 KB |
Partially correct |
8 |
Partially correct |
76 ms |
7756 KB |
Partially correct |
9 |
Partially correct |
192 ms |
8276 KB |
Partially correct |
10 |
Partially correct |
220 ms |
8124 KB |
Partially correct |
11 |
Partially correct |
157 ms |
8036 KB |
Partially correct |
12 |
Partially correct |
102 ms |
8136 KB |
Partially correct |
13 |
Partially correct |
276 ms |
7864 KB |
Partially correct |
14 |
Partially correct |
74 ms |
7840 KB |
Partially correct |
15 |
Partially correct |
78 ms |
8292 KB |
Partially correct |
16 |
Partially correct |
221 ms |
8056 KB |
Partially correct |
17 |
Partially correct |
229 ms |
8060 KB |
Partially correct |
18 |
Partially correct |
114 ms |
7844 KB |
Partially correct |
19 |
Partially correct |
89 ms |
7868 KB |
Partially correct |
20 |
Partially correct |
138 ms |
8120 KB |
Partially correct |
21 |
Partially correct |
73 ms |
7772 KB |
Partially correct |
22 |
Partially correct |
78 ms |
7836 KB |
Partially correct |
23 |
Partially correct |
207 ms |
8092 KB |
Partially correct |
24 |
Partially correct |
208 ms |
8068 KB |
Partially correct |
25 |
Partially correct |
90 ms |
8104 KB |
Partially correct |
26 |
Partially correct |
86 ms |
7960 KB |
Partially correct |
27 |
Partially correct |
90 ms |
8124 KB |
Partially correct |
28 |
Partially correct |
79 ms |
7776 KB |
Partially correct |
29 |
Partially correct |
79 ms |
7872 KB |
Partially correct |
30 |
Partially correct |
216 ms |
7872 KB |
Partially correct |
31 |
Partially correct |
199 ms |
8036 KB |
Partially correct |
32 |
Partially correct |
83 ms |
7952 KB |
Partially correct |
33 |
Partially correct |
241 ms |
8132 KB |
Partially correct |
34 |
Partially correct |
230 ms |
8284 KB |
Partially correct |
35 |
Partially correct |
83 ms |
8052 KB |
Partially correct |
36 |
Partially correct |
82 ms |
8276 KB |
Partially correct |
37 |
Partially correct |
189 ms |
7868 KB |
Partially correct |
38 |
Partially correct |
204 ms |
8060 KB |
Partially correct |
39 |
Partially correct |
239 ms |
7868 KB |
Partially correct |
40 |
Partially correct |
145 ms |
8064 KB |
Partially correct |
41 |
Partially correct |
202 ms |
8092 KB |
Partially correct |
42 |
Partially correct |
84 ms |
8036 KB |
Partially correct |
43 |
Partially correct |
81 ms |
8032 KB |
Partially correct |
44 |
Partially correct |
222 ms |
8064 KB |
Partially correct |
45 |
Partially correct |
193 ms |
7872 KB |
Partially correct |
46 |
Partially correct |
84 ms |
7848 KB |
Partially correct |
47 |
Partially correct |
71 ms |
7840 KB |
Partially correct |
48 |
Partially correct |
90 ms |
8268 KB |
Partially correct |
49 |
Partially correct |
73 ms |
7772 KB |
Partially correct |
50 |
Partially correct |
76 ms |
8100 KB |
Partially correct |
51 |
Correct |
83 ms |
8936 KB |
Correct |
52 |
Correct |
82 ms |
8860 KB |
Correct |
53 |
Correct |
83 ms |
8932 KB |
Correct |
54 |
Correct |
96 ms |
8804 KB |
Correct |
55 |
Correct |
156 ms |
8964 KB |
Correct |
56 |
Correct |
164 ms |
8908 KB |
Correct |
57 |
Correct |
94 ms |
8824 KB |
Correct |
58 |
Correct |
81 ms |
8668 KB |
Correct |
59 |
Correct |
84 ms |
8712 KB |
Correct |
60 |
Correct |
77 ms |
8756 KB |
Correct |
61 |
Correct |
79 ms |
8680 KB |
Correct |
62 |
Correct |
72 ms |
8792 KB |
Correct |
63 |
Correct |
74 ms |
8764 KB |
Correct |
64 |
Correct |
65 ms |
6628 KB |
Correct |
65 |
Correct |
59 ms |
6644 KB |
Correct |
66 |
Correct |
80 ms |
8784 KB |
Correct |
67 |
Correct |
75 ms |
8964 KB |
Correct |
68 |
Correct |
89 ms |
8676 KB |
Correct |
69 |
Correct |
81 ms |
8720 KB |
Correct |
70 |
Correct |
61 ms |
6552 KB |
Correct |
71 |
Correct |
56 ms |
6780 KB |
Correct |
72 |
Correct |
62 ms |
6720 KB |
Correct |
73 |
Correct |
60 ms |
6664 KB |
Correct |
74 |
Correct |
61 ms |
6576 KB |
Correct |
75 |
Correct |
55 ms |
6728 KB |
Correct |
76 |
Correct |
80 ms |
8684 KB |
Correct |
77 |
Correct |
80 ms |
8708 KB |
Correct |
78 |
Correct |
86 ms |
8956 KB |
Correct |
79 |
Correct |
82 ms |
8832 KB |
Correct |
80 |
Correct |
92 ms |
8988 KB |
Correct |
81 |
Correct |
86 ms |
9016 KB |
Correct |
82 |
Correct |
89 ms |
8680 KB |
Correct |
83 |
Correct |
80 ms |
8896 KB |
Correct |
84 |
Correct |
82 ms |
8968 KB |
Correct |
85 |
Correct |
83 ms |
8764 KB |
Correct |
86 |
Correct |
84 ms |
9024 KB |
Correct |
87 |
Correct |
92 ms |
8760 KB |
Correct |
88 |
Correct |
82 ms |
8948 KB |
Correct |
89 |
Correct |
95 ms |
8952 KB |
Correct |
90 |
Correct |
83 ms |
8764 KB |
Correct |
91 |
Correct |
88 ms |
8880 KB |
Correct |
92 |
Correct |
81 ms |
8696 KB |
Correct |
93 |
Correct |
82 ms |
8860 KB |
Correct |
94 |
Correct |
82 ms |
8880 KB |
Correct |
95 |
Correct |
89 ms |
8824 KB |
Correct |
96 |
Correct |
82 ms |
8940 KB |
Correct |
97 |
Correct |
93 ms |
8948 KB |
Correct |
98 |
Correct |
81 ms |
8768 KB |
Correct |
99 |
Correct |
70 ms |
8712 KB |
Correct |
100 |
Correct |
84 ms |
8952 KB |
Correct |
101 |
Correct |
94 ms |
8936 KB |
Correct |
102 |
Correct |
92 ms |
8764 KB |
Correct |
103 |
Correct |
75 ms |
8872 KB |
Correct |
104 |
Correct |
63 ms |
8868 KB |
Correct |
105 |
Correct |
78 ms |
9044 KB |
Correct |
106 |
Correct |
86 ms |
8924 KB |
Correct |
107 |
Correct |
74 ms |
8572 KB |
Correct |
108 |
Correct |
81 ms |
8740 KB |
Correct |
109 |
Correct |
80 ms |
8684 KB |
Correct |
110 |
Correct |
92 ms |
8732 KB |
Correct |
111 |
Correct |
77 ms |
8736 KB |
Correct |
112 |
Correct |
89 ms |
8736 KB |
Correct |
113 |
Correct |
82 ms |
8740 KB |
Correct |
114 |
Correct |
84 ms |
8660 KB |
Correct |
115 |
Correct |
96 ms |
8596 KB |
Correct |
116 |
Incorrect |
83 ms |
8792 KB |
Not correct |
117 |
Halted |
0 ms |
0 KB |
- |