#include <bits/stdc++.h>
#include "highway.h"
using namespace std;
const long long MAXN = 1e5 + 7;
long long ask(const vector<int> &w);
void answer(int s, int t);
mt19937 mt(1);
long long n, m;
vector<int> adj[MAXN], idx[MAXN], w;
bool used[MAXN];
long long a, b;
long long sm;
queue<long long> q;
vector<int> temp;
vector<pair<long long, long long> > bfs(long long x){
for(long long i = 0; i < n; i++){
used[i] = false;
}
q.push(x);
vector<pair<long long, long long> > v;
while(!q.empty()){
long long u = q.front();
q.pop();
if(used[u]){
continue;
}
used[u] = true;
temp.clear();
for(int i = 0; i < (int)adj[u].size(); i++){
temp.push_back(i);
}
for(int i = 0; i < (int)adj[u].size(); i++){
int x = mt() % adj[u].size();
int y = mt() % adj[u].size();
swap(temp[x], temp[y]);
}
for(long long i = 0; i < adj[u].size(); i++){
long long to = adj[u][i];
long long j = idx[u][i];
if(!used[to]){
v.push_back({j, to});
}
}
for(long long i = 0; i < adj[u].size(); i++){
long long to = adj[u][temp[i]];
long long j = idx[u][temp[i]];
if(!used[to]){
q.push(to);
}
}
}
return v;
}
long long away(int x, const vector<int> &U, const vector<int> &V){
vector<pair<long long, long long> > v = bfs(x);
while((long long)v.size() != m);
long long l = 0, r = (long long)v.size() - 1;
while(l != r){
long long mid = (l + r) >> 1;
for(long long i = 0; i < m; i++){
w[i] = 0;
}
for(long long i = 0; i <= mid; i++){
w[ v[i].first ] = 1;
}
long long score = ask(w);
if(score == (sm / a) * b){
r = mid;
}
else{
l = mid + 1;
}
}
return v[l].second;
}
void find_pair(int N, vector<int> U, vector<int> V, int A, int B){
srand(time(NULL));
n = N;
m = U.size();
for(long long i = 0; i < m; i++){
adj[V[i]].push_back(U[i]);
adj[U[i]].push_back(V[i]);
idx[V[i]].push_back(i);
idx[U[i]].push_back(i);
w.push_back(0);
}
sm = ask(w);
a = A;
b = B;
long long l = 0, r = m - 1;
while(l != r){
long long mid = (l + r) / 2;
for(long long i = 0; i < m; i++){
w[i] = 0;
}
for(long long i = mid + 1; i <= r; i++){
w[i] = 1;
}
long long score = ask(w);
score -= sm;
if(score){
l = mid + 1;
}
else{
r = mid;
}
}
long long x, y;
x = away(U[l], U, V);
y = away(x, U, V);
answer(x, y);
}
/*
9 1 2
4 8
4 2
8 0
2 5
2 7
2 3
0 1
0 6
*/
Compilation message
highway.cpp: In function 'std::vector<std::pair<long long int, long long int> > bfs(long long int)':
highway.cpp:54:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(long long i = 0; i < adj[u].size(); i++){
~~^~~~~~~~~~~~~~~
highway.cpp:63:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(long long i = 0; i < adj[u].size(); i++){
~~^~~~~~~~~~~~~~~
highway.cpp:65:14: warning: unused variable 'j' [-Wunused-variable]
long long j = idx[u][temp[i]];
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4988 KB |
Output is correct |
2 |
Correct |
6 ms |
4984 KB |
Output is correct |
3 |
Correct |
7 ms |
4984 KB |
Output is correct |
4 |
Correct |
6 ms |
5024 KB |
Output is correct |
5 |
Correct |
7 ms |
5032 KB |
Output is correct |
6 |
Correct |
6 ms |
5032 KB |
Output is correct |
7 |
Correct |
6 ms |
5112 KB |
Output is correct |
8 |
Correct |
7 ms |
5024 KB |
Output is correct |
9 |
Correct |
6 ms |
4984 KB |
Output is correct |
10 |
Correct |
6 ms |
5032 KB |
Output is correct |
11 |
Correct |
7 ms |
4984 KB |
Output is correct |
12 |
Correct |
7 ms |
4984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
5032 KB |
Output is correct |
2 |
Correct |
32 ms |
6264 KB |
Output is correct |
3 |
Correct |
312 ms |
16204 KB |
Output is correct |
4 |
Correct |
291 ms |
16248 KB |
Output is correct |
5 |
Correct |
268 ms |
16236 KB |
Output is correct |
6 |
Correct |
306 ms |
16232 KB |
Output is correct |
7 |
Correct |
273 ms |
16348 KB |
Output is correct |
8 |
Correct |
238 ms |
16248 KB |
Output is correct |
9 |
Correct |
341 ms |
16340 KB |
Output is correct |
10 |
Correct |
251 ms |
16212 KB |
Output is correct |
11 |
Correct |
262 ms |
16016 KB |
Output is correct |
12 |
Correct |
310 ms |
16116 KB |
Output is correct |
13 |
Correct |
281 ms |
16004 KB |
Output is correct |
14 |
Correct |
273 ms |
16048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
6244 KB |
Output is correct |
2 |
Correct |
64 ms |
7508 KB |
Output is correct |
3 |
Correct |
63 ms |
8448 KB |
Output is correct |
4 |
Correct |
220 ms |
16008 KB |
Output is correct |
5 |
Correct |
201 ms |
15988 KB |
Output is correct |
6 |
Correct |
202 ms |
15992 KB |
Output is correct |
7 |
Correct |
172 ms |
15996 KB |
Output is correct |
8 |
Correct |
184 ms |
16012 KB |
Output is correct |
9 |
Correct |
163 ms |
15940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
5192 KB |
Output is correct |
2 |
Correct |
34 ms |
6252 KB |
Output is correct |
3 |
Correct |
223 ms |
14212 KB |
Output is correct |
4 |
Correct |
307 ms |
16204 KB |
Output is correct |
5 |
Correct |
247 ms |
16216 KB |
Output is correct |
6 |
Correct |
283 ms |
16220 KB |
Output is correct |
7 |
Correct |
266 ms |
16240 KB |
Output is correct |
8 |
Correct |
261 ms |
16232 KB |
Output is correct |
9 |
Correct |
305 ms |
16432 KB |
Output is correct |
10 |
Correct |
309 ms |
16304 KB |
Output is correct |
11 |
Correct |
322 ms |
16008 KB |
Output is correct |
12 |
Correct |
297 ms |
16012 KB |
Output is correct |
13 |
Correct |
315 ms |
16004 KB |
Output is correct |
14 |
Correct |
326 ms |
15992 KB |
Output is correct |
15 |
Correct |
263 ms |
16224 KB |
Output is correct |
16 |
Correct |
298 ms |
16236 KB |
Output is correct |
17 |
Correct |
278 ms |
15992 KB |
Output is correct |
18 |
Correct |
347 ms |
15996 KB |
Output is correct |
19 |
Correct |
279 ms |
16240 KB |
Output is correct |
20 |
Correct |
228 ms |
16032 KB |
Output is correct |
21 |
Correct |
239 ms |
17296 KB |
Output is correct |
22 |
Correct |
208 ms |
17288 KB |
Output is correct |
23 |
Correct |
252 ms |
17008 KB |
Output is correct |
24 |
Correct |
255 ms |
16992 KB |
Output is correct |
25 |
Correct |
317 ms |
16152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
6308 KB |
Output is correct |
2 |
Incorrect |
39 ms |
6388 KB |
Output is incorrect: {s, t} is wrong. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
47 ms |
6292 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |