#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;
vector<pair<int, int>> d[nx], t[nx];
queue<int> q;
void dfs(int u)
{
//printf("dfs %d\n", 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;
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}), vs[v]=1, q.push(v);
}
id[0]={ls, l};
dfs(ls);
nl=0; nr=cnt;
while (nl<nr)
{
int md=(nl+nr+1)/2;
for (int i=0; i<m; i++) qrs[i]=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 (int i=0; i<m; i++) qrs[i]=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);
}
/*
4 3 1 2 0 3
0 1
0 2
1 3
*/
/*
6 5 1 2 2 4
0 1
0 2
1 3
1 5
5 4
8 7 1 2 2 7
0 1
0 5
5 6
5 4
4 7
1 3
1 2
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
5148 KB |
Output is correct |
2 |
Correct |
2 ms |
5152 KB |
Output is correct |
3 |
Correct |
3 ms |
5156 KB |
Output is correct |
4 |
Correct |
2 ms |
5152 KB |
Output is correct |
5 |
Correct |
1 ms |
5148 KB |
Output is correct |
6 |
Correct |
2 ms |
5148 KB |
Output is correct |
7 |
Correct |
2 ms |
5152 KB |
Output is correct |
8 |
Correct |
1 ms |
5152 KB |
Output is correct |
9 |
Correct |
2 ms |
5152 KB |
Output is correct |
10 |
Correct |
1 ms |
5156 KB |
Output is correct |
11 |
Correct |
1 ms |
5152 KB |
Output is correct |
12 |
Correct |
2 ms |
5148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5200 KB |
Output is correct |
2 |
Correct |
13 ms |
6220 KB |
Output is correct |
3 |
Correct |
99 ms |
13380 KB |
Output is correct |
4 |
Correct |
88 ms |
13368 KB |
Output is correct |
5 |
Correct |
86 ms |
13368 KB |
Output is correct |
6 |
Correct |
86 ms |
13620 KB |
Output is correct |
7 |
Correct |
86 ms |
13364 KB |
Output is correct |
8 |
Correct |
92 ms |
13368 KB |
Output is correct |
9 |
Correct |
102 ms |
13212 KB |
Output is correct |
10 |
Correct |
84 ms |
13380 KB |
Output is correct |
11 |
Correct |
96 ms |
14060 KB |
Output is correct |
12 |
Correct |
122 ms |
14400 KB |
Output is correct |
13 |
Correct |
99 ms |
14292 KB |
Output is correct |
14 |
Correct |
119 ms |
14348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
6328 KB |
Output is correct |
2 |
Correct |
18 ms |
7108 KB |
Output is correct |
3 |
Correct |
30 ms |
8504 KB |
Output is correct |
4 |
Correct |
77 ms |
14524 KB |
Output is correct |
5 |
Correct |
84 ms |
15080 KB |
Output is correct |
6 |
Correct |
117 ms |
15136 KB |
Output is correct |
7 |
Correct |
71 ms |
15400 KB |
Output is correct |
8 |
Correct |
70 ms |
14724 KB |
Output is correct |
9 |
Correct |
91 ms |
14968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
5200 KB |
Output is correct |
2 |
Correct |
11 ms |
5968 KB |
Output is correct |
3 |
Correct |
89 ms |
11552 KB |
Output is correct |
4 |
Correct |
115 ms |
13340 KB |
Output is correct |
5 |
Correct |
85 ms |
13592 KB |
Output is correct |
6 |
Correct |
93 ms |
13368 KB |
Output is correct |
7 |
Correct |
94 ms |
13620 KB |
Output is correct |
8 |
Correct |
82 ms |
13572 KB |
Output is correct |
9 |
Correct |
97 ms |
13128 KB |
Output is correct |
10 |
Correct |
112 ms |
13372 KB |
Output is correct |
11 |
Correct |
117 ms |
14224 KB |
Output is correct |
12 |
Correct |
89 ms |
14288 KB |
Output is correct |
13 |
Correct |
111 ms |
14372 KB |
Output is correct |
14 |
Correct |
97 ms |
14164 KB |
Output is correct |
15 |
Correct |
93 ms |
13404 KB |
Output is correct |
16 |
Correct |
87 ms |
13372 KB |
Output is correct |
17 |
Correct |
99 ms |
14508 KB |
Output is correct |
18 |
Correct |
96 ms |
14340 KB |
Output is correct |
19 |
Correct |
101 ms |
13368 KB |
Output is correct |
20 |
Correct |
95 ms |
14460 KB |
Output is correct |
21 |
Correct |
67 ms |
13832 KB |
Output is correct |
22 |
Correct |
74 ms |
13580 KB |
Output is correct |
23 |
Correct |
111 ms |
12772 KB |
Output is correct |
24 |
Correct |
80 ms |
13400 KB |
Output is correct |
25 |
Correct |
110 ms |
15400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
6248 KB |
Output is correct |
2 |
Correct |
18 ms |
6068 KB |
Output is correct |
3 |
Correct |
113 ms |
13436 KB |
Output is correct |
4 |
Correct |
150 ms |
14156 KB |
Output is correct |
5 |
Correct |
143 ms |
14680 KB |
Output is correct |
6 |
Incorrect |
156 ms |
14840 KB |
Output is incorrect: {s, t} is wrong. |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
6248 KB |
Output is correct |
2 |
Correct |
13 ms |
6040 KB |
Output is correct |
3 |
Correct |
127 ms |
13784 KB |
Output is correct |
4 |
Correct |
111 ms |
13932 KB |
Output is correct |
5 |
Correct |
147 ms |
14268 KB |
Output is correct |
6 |
Incorrect |
115 ms |
14800 KB |
Output is incorrect: {s, t} is wrong. |
7 |
Halted |
0 ms |
0 KB |
- |