#include <iostream>
#include <complex>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <functional>
#include <bitset>
#include <queue>
#include <map>
#include <stack>
#include <cmath>
#include <cstdint>
#include "highway.h"
using namespace std;
#define endl '\n'
#define db double
#define ll long long
#define pb push_back
#define fs first
#define sd second
#define Mod long(1e9 + 7)
#define all(x) x.begin(), x.end()
#define unvisited long(-1)
#define Eps double(1e-9)
#define _for(i, n) for(int i = 0; i < (n); i++)
#define dbg(x) cout << #x ": " << x << endl;
const int Max = 1e6 + 7, Inf = 1e9 + 7;
long long ask(const std::vector<int> &w);
void answer(int s, int t);
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B)
{
int M = U.size(), S, T;
vector <vector<pair<int, int>>> v(N + 1, vector <pair<int, int>> ());
for(int i = 0; i < M; i++)
{
int a = U[i], b = V[i];
v[a].push_back({ b, i });
v[b].push_back({ a, i });
}
vector <int> d(N+1), w(M);
long long ivalue = ask(w);
vector <pair<int, int>> p(N+1, { 0, -1 }), t;
auto Cdist = [&] (auto Cdist, int node, int parent) -> void
{
if(parent != -1) t.push_back({ d[node], p[node].sd });
for(auto& u : v[node]) if(u.fs != parent)
{
d[u.fs] = d[node] + 1;
p[u.fs].fs = node;
p[u.fs].sd = u.sd;
Cdist(Cdist, u.fs, node);
}
}; Cdist(Cdist, 0, -1);
sort(all(t)); reverse(all(t));
int a = -1, b = t.size()-1;
while (abs(a - b) != 1)
{
int c = (a + b) / 2;
for(int i = 0; i < M; i++){
if(i <= c)
w[t[i].sd] = 1;
else
w[t[i].sd] = 0;
}
if(ask(w) != ivalue)
b = c;
else
a = c;
}
b = t[b].sd;
if(d[U[b]] > d[V[b]])
S = U[b];
else
S = V[b];
for(int i = 0; i < M; i++){
w[i] = 1;
}
int x = S;
vector <int> f(M);
while (x != 0){
f[p[x].sd] = 1;
w[p[x].sd] = 0;
x = p[x].fs;
}
if(ask(w) != ivalue)
{
a = -1; b = t.size()-1;
while (abs(a - b) != 1)
{
int c = (a + b) / 2;
for(int i = 0; i < M; i++){
if(i <= c && f[t[i].sd] == 0)
w[t[i].sd] = 1;
else
w[t[i].sd] = 0;
}
if(ask(w) != ivalue)
b = c;
else
a = c;
}
b = t[b].sd;
if(d[U[b]] > d[V[b]])
T = U[b];
else
T = V[b];
}
else
{
vector <pair<int, int>> tx;
for(int i = 0; i < M; i++)
{
if(f[t[i].sd] == 1){
tx.push_back(t[i]);
//cerr << U[t[i].sd] << " " << V[t[i].sd] << endl;
}
} t = tx; reverse(all(t));
a = -1; b = t.size()-1;
while (abs(a - b) != 1)
{
int c = (a + b) / 2;
for(int i = 0; i < M; i++){
w[i] = 0;
}
for(int i = 0; i < M; i++){
if(i <= c)
w[t[i].sd] = 1;
}
if(ask(w) != ivalue)
b = c;
else
a = c;
}
b = t[b].sd;
if(d[U[b]] < d[V[b]])
T = U[b];
else
T = V[b];
}
answer(S, T);
}
/*
N M A B S T
U[i] V[i]
4 3 1 2 2 3
0 1
1 2
1 3
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
448 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
8 ms |
1368 KB |
Output is correct |
3 |
Correct |
97 ms |
9776 KB |
Output is correct |
4 |
Correct |
90 ms |
9796 KB |
Output is correct |
5 |
Correct |
85 ms |
9780 KB |
Output is correct |
6 |
Correct |
83 ms |
9908 KB |
Output is correct |
7 |
Correct |
78 ms |
9676 KB |
Output is correct |
8 |
Correct |
84 ms |
9788 KB |
Output is correct |
9 |
Correct |
78 ms |
9692 KB |
Output is correct |
10 |
Correct |
87 ms |
9692 KB |
Output is correct |
11 |
Correct |
85 ms |
10440 KB |
Output is correct |
12 |
Correct |
82 ms |
10988 KB |
Output is correct |
13 |
Correct |
91 ms |
10508 KB |
Output is correct |
14 |
Correct |
80 ms |
10184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
1880 KB |
Output is correct |
2 |
Correct |
15 ms |
3496 KB |
Output is correct |
3 |
Correct |
24 ms |
5240 KB |
Output is correct |
4 |
Correct |
69 ms |
14652 KB |
Output is correct |
5 |
Correct |
63 ms |
14524 KB |
Output is correct |
6 |
Correct |
67 ms |
15180 KB |
Output is correct |
7 |
Correct |
73 ms |
15276 KB |
Output is correct |
8 |
Correct |
70 ms |
14696 KB |
Output is correct |
9 |
Correct |
69 ms |
15464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
344 KB |
Output is correct |
2 |
Correct |
9 ms |
1584 KB |
Output is correct |
3 |
Correct |
63 ms |
8020 KB |
Output is correct |
4 |
Correct |
93 ms |
9788 KB |
Output is correct |
5 |
Correct |
79 ms |
9652 KB |
Output is correct |
6 |
Correct |
89 ms |
9788 KB |
Output is correct |
7 |
Correct |
84 ms |
9808 KB |
Output is correct |
8 |
Correct |
96 ms |
9784 KB |
Output is correct |
9 |
Correct |
96 ms |
9752 KB |
Output is correct |
10 |
Correct |
95 ms |
9772 KB |
Output is correct |
11 |
Correct |
96 ms |
10276 KB |
Output is correct |
12 |
Correct |
104 ms |
10952 KB |
Output is correct |
13 |
Correct |
80 ms |
10940 KB |
Output is correct |
14 |
Correct |
82 ms |
11316 KB |
Output is correct |
15 |
Correct |
90 ms |
9932 KB |
Output is correct |
16 |
Correct |
78 ms |
9684 KB |
Output is correct |
17 |
Correct |
105 ms |
10712 KB |
Output is correct |
18 |
Correct |
93 ms |
10440 KB |
Output is correct |
19 |
Correct |
85 ms |
9808 KB |
Output is correct |
20 |
Correct |
89 ms |
11992 KB |
Output is correct |
21 |
Correct |
68 ms |
10180 KB |
Output is correct |
22 |
Correct |
72 ms |
10180 KB |
Output is correct |
23 |
Correct |
91 ms |
9984 KB |
Output is correct |
24 |
Correct |
84 ms |
10432 KB |
Output is correct |
25 |
Correct |
89 ms |
13440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
266 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
262 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |