#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int nx=1e5+5;
ll m, res, l, r, ls, rs, vs[nx], cnt, nl, nr;
pair<int, int> id[nx], ans;
vector<int> qrs, used;
vector<pair<int, int>> d[nx], t[nx];
queue<int> q;
void dfs(int u)
{
for (auto [v, idx]:t[u]) id[++cnt]={v, idx}, dfs(v);
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
m=U.size();
qrs.resize(U.size());
for (int i=0; i<m; i++) qrs[i]=0, d[U[i]].push_back({V[i], i}), d[V[i]].push_back({U[i], i});
res=ask(qrs);
l=0; r=m-1;
while (l<r)
{
int md=(l+r)/2;
for (int i=0; i<m; i++) qrs[i]=i>md;
if (ask(qrs)!=res) l=md+1;
else r=md;
}
ls=U[l];
rs=V[l];
//cout<<"edge "<<ls<<' '<<rs<<'\n';
vs[ls]=vs[rs]=1;
used.push_back(l);
q.push(ls);
q.push(rs);
while (!q.empty())
{
auto u=q.front();
q.pop();
for (auto [v, idx]:d[u]) if (!vs[v]) t[u].push_back({v, idx}), used.push_back(idx), vs[v]=1, q.push(v);
}
//cout<<"edge "<<ls<<' '<<rs<<'\n';
//for (int i=0; i<m; i++) cout<<used[i]<<' ';
//cout<<'\n';
id[0]={ls, l};
dfs(ls);
nl=0; nr=cnt;
for (int i=0; i<m; i++) qrs[i]=1;
while (nl<nr)
{
int md=(nl+nr+1)/2;
for (auto x:used) qrs[x]=0;
for (int i=md; i<=nr; i++) qrs[id[i].second]=1;
if (ask(qrs)!=res) nl=md;
else nr=md-1;
}
ans.first=id[nl].first;
id[0]={rs, l};
cnt=0;
dfs(rs);
nl=0; nr=cnt;
while (nl<nr)
{
int md=(nl+nr+1)/2;
for (auto x:used) qrs[x]=0;
for (int i=md; i<=nr; i++) qrs[id[i].second]=1;
if (ask(qrs)!=res) nl=md;
else nr=md-1;
}
ans.second=id[nl].first;
answer(ans.first, ans.second);
}
/*
3 3 1 2 0 1
0 1
1 2
2 0
4 4 1 3 1 3
0 1
0 2
0 3
1 2
3 6 1 2 1 2
0 1
0 1
1 2
1 2
2 0
2 0
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5152 KB |
Output is correct |
2 |
Correct |
2 ms |
5152 KB |
Output is correct |
3 |
Correct |
2 ms |
5156 KB |
Output is correct |
4 |
Correct |
1 ms |
5148 KB |
Output is correct |
5 |
Correct |
2 ms |
5144 KB |
Output is correct |
6 |
Correct |
2 ms |
5148 KB |
Output is correct |
7 |
Correct |
2 ms |
5152 KB |
Output is correct |
8 |
Correct |
2 ms |
5148 KB |
Output is correct |
9 |
Correct |
1 ms |
5148 KB |
Output is correct |
10 |
Correct |
2 ms |
5152 KB |
Output is correct |
11 |
Correct |
2 ms |
5152 KB |
Output is correct |
12 |
Correct |
2 ms |
5148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5200 KB |
Output is correct |
2 |
Correct |
11 ms |
6116 KB |
Output is correct |
3 |
Correct |
99 ms |
13712 KB |
Output is correct |
4 |
Correct |
95 ms |
13908 KB |
Output is correct |
5 |
Correct |
84 ms |
13728 KB |
Output is correct |
6 |
Correct |
86 ms |
13952 KB |
Output is correct |
7 |
Correct |
88 ms |
13764 KB |
Output is correct |
8 |
Correct |
108 ms |
13872 KB |
Output is correct |
9 |
Correct |
88 ms |
13816 KB |
Output is correct |
10 |
Correct |
87 ms |
13728 KB |
Output is correct |
11 |
Correct |
108 ms |
14816 KB |
Output is correct |
12 |
Correct |
102 ms |
14660 KB |
Output is correct |
13 |
Correct |
105 ms |
14912 KB |
Output is correct |
14 |
Correct |
155 ms |
14940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
6128 KB |
Output is correct |
2 |
Correct |
17 ms |
7192 KB |
Output is correct |
3 |
Correct |
26 ms |
8560 KB |
Output is correct |
4 |
Correct |
109 ms |
14880 KB |
Output is correct |
5 |
Correct |
73 ms |
15032 KB |
Output is correct |
6 |
Correct |
79 ms |
15492 KB |
Output is correct |
7 |
Correct |
86 ms |
15748 KB |
Output is correct |
8 |
Correct |
73 ms |
15080 KB |
Output is correct |
9 |
Correct |
68 ms |
15528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5204 KB |
Output is correct |
2 |
Correct |
14 ms |
5964 KB |
Output is correct |
3 |
Correct |
71 ms |
11844 KB |
Output is correct |
4 |
Correct |
110 ms |
13944 KB |
Output is correct |
5 |
Correct |
105 ms |
13716 KB |
Output is correct |
6 |
Correct |
146 ms |
13988 KB |
Output is correct |
7 |
Correct |
85 ms |
13956 KB |
Output is correct |
8 |
Correct |
91 ms |
13720 KB |
Output is correct |
9 |
Correct |
99 ms |
13488 KB |
Output is correct |
10 |
Correct |
111 ms |
13720 KB |
Output is correct |
11 |
Correct |
103 ms |
14592 KB |
Output is correct |
12 |
Correct |
108 ms |
14884 KB |
Output is correct |
13 |
Correct |
147 ms |
14736 KB |
Output is correct |
14 |
Correct |
109 ms |
14520 KB |
Output is correct |
15 |
Correct |
80 ms |
13748 KB |
Output is correct |
16 |
Correct |
86 ms |
13768 KB |
Output is correct |
17 |
Correct |
95 ms |
14864 KB |
Output is correct |
18 |
Correct |
111 ms |
14680 KB |
Output is correct |
19 |
Correct |
83 ms |
13724 KB |
Output is correct |
20 |
Correct |
97 ms |
14836 KB |
Output is correct |
21 |
Correct |
74 ms |
14436 KB |
Output is correct |
22 |
Correct |
79 ms |
14440 KB |
Output is correct |
23 |
Correct |
75 ms |
13496 KB |
Output is correct |
24 |
Correct |
84 ms |
13172 KB |
Output is correct |
25 |
Correct |
108 ms |
15508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
6248 KB |
Output is correct |
2 |
Correct |
11 ms |
6180 KB |
Output is correct |
3 |
Correct |
103 ms |
13940 KB |
Output is correct |
4 |
Correct |
103 ms |
14684 KB |
Output is correct |
5 |
Correct |
148 ms |
15364 KB |
Output is correct |
6 |
Correct |
134 ms |
15860 KB |
Output is correct |
7 |
Correct |
172 ms |
15540 KB |
Output is correct |
8 |
Correct |
155 ms |
15692 KB |
Output is correct |
9 |
Correct |
101 ms |
11800 KB |
Output is correct |
10 |
Correct |
101 ms |
12596 KB |
Output is correct |
11 |
Correct |
95 ms |
13028 KB |
Output is correct |
12 |
Correct |
128 ms |
14572 KB |
Output is correct |
13 |
Correct |
118 ms |
15020 KB |
Output is correct |
14 |
Correct |
141 ms |
15516 KB |
Output is correct |
15 |
Correct |
135 ms |
15880 KB |
Output is correct |
16 |
Correct |
148 ms |
13008 KB |
Output is correct |
17 |
Correct |
82 ms |
13712 KB |
Output is correct |
18 |
Correct |
62 ms |
13640 KB |
Output is correct |
19 |
Correct |
84 ms |
13708 KB |
Output is correct |
20 |
Correct |
85 ms |
13736 KB |
Output is correct |
21 |
Correct |
137 ms |
15800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
6248 KB |
Output is correct |
2 |
Correct |
13 ms |
6160 KB |
Output is correct |
3 |
Correct |
107 ms |
14568 KB |
Output is correct |
4 |
Correct |
109 ms |
14260 KB |
Output is correct |
5 |
Correct |
143 ms |
15156 KB |
Output is correct |
6 |
Correct |
138 ms |
15376 KB |
Output is correct |
7 |
Correct |
105 ms |
14004 KB |
Output is correct |
8 |
Correct |
110 ms |
14244 KB |
Output is correct |
9 |
Correct |
112 ms |
14760 KB |
Output is correct |
10 |
Correct |
174 ms |
15600 KB |
Output is correct |
11 |
Correct |
159 ms |
15648 KB |
Output is correct |
12 |
Correct |
156 ms |
15360 KB |
Output is correct |
13 |
Correct |
135 ms |
13396 KB |
Output is correct |
14 |
Correct |
89 ms |
13052 KB |
Output is correct |
15 |
Correct |
125 ms |
13252 KB |
Output is correct |
16 |
Correct |
99 ms |
12856 KB |
Output is correct |
17 |
Correct |
101 ms |
13240 KB |
Output is correct |
18 |
Correct |
90 ms |
12636 KB |
Output is correct |
19 |
Correct |
143 ms |
14708 KB |
Output is correct |
20 |
Correct |
137 ms |
15076 KB |
Output is correct |
21 |
Correct |
150 ms |
15880 KB |
Output is correct |
22 |
Correct |
137 ms |
15540 KB |
Output is correct |
23 |
Correct |
164 ms |
15728 KB |
Output is correct |
24 |
Correct |
148 ms |
15476 KB |
Output is correct |
25 |
Correct |
182 ms |
15728 KB |
Output is correct |
26 |
Correct |
144 ms |
16072 KB |
Output is correct |
27 |
Correct |
111 ms |
13640 KB |
Output is correct |
28 |
Correct |
76 ms |
13436 KB |
Output is correct |
29 |
Correct |
81 ms |
13996 KB |
Output is correct |
30 |
Correct |
81 ms |
13868 KB |
Output is correct |
31 |
Correct |
87 ms |
13592 KB |
Output is correct |
32 |
Correct |
76 ms |
13404 KB |
Output is correct |
33 |
Correct |
81 ms |
13864 KB |
Output is correct |
34 |
Correct |
82 ms |
13892 KB |
Output is correct |
35 |
Correct |
75 ms |
13804 KB |
Output is correct |
36 |
Correct |
84 ms |
13340 KB |
Output is correct |
37 |
Correct |
86 ms |
13816 KB |
Output is correct |
38 |
Correct |
73 ms |
13860 KB |
Output is correct |
39 |
Correct |
166 ms |
15844 KB |
Output is correct |
40 |
Correct |
178 ms |
15668 KB |
Output is correct |
41 |
Correct |
210 ms |
15936 KB |
Output is correct |
42 |
Correct |
151 ms |
15416 KB |
Output is correct |