#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();
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<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;
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]){
q.push(to);
v.push_back({j, 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:40:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(long long i = 0; i < adj[u].size(); i++){
~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4924 KB |
Output is correct |
2 |
Correct |
6 ms |
5024 KB |
Output is correct |
3 |
Correct |
6 ms |
5024 KB |
Output is correct |
4 |
Correct |
6 ms |
5024 KB |
Output is correct |
5 |
Correct |
6 ms |
5020 KB |
Output is correct |
6 |
Correct |
6 ms |
5024 KB |
Output is correct |
7 |
Correct |
6 ms |
5032 KB |
Output is correct |
8 |
Correct |
7 ms |
5024 KB |
Output is correct |
9 |
Correct |
6 ms |
5024 KB |
Output is correct |
10 |
Correct |
6 ms |
4904 KB |
Output is correct |
11 |
Correct |
6 ms |
5020 KB |
Output is correct |
12 |
Correct |
6 ms |
5024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
5100 KB |
Output is correct |
2 |
Correct |
42 ms |
6272 KB |
Output is correct |
3 |
Correct |
301 ms |
16224 KB |
Output is correct |
4 |
Correct |
264 ms |
16232 KB |
Output is correct |
5 |
Correct |
249 ms |
16224 KB |
Output is correct |
6 |
Correct |
278 ms |
16216 KB |
Output is correct |
7 |
Correct |
225 ms |
16216 KB |
Output is correct |
8 |
Correct |
280 ms |
16232 KB |
Output is correct |
9 |
Correct |
244 ms |
16228 KB |
Output is correct |
10 |
Correct |
237 ms |
16208 KB |
Output is correct |
11 |
Correct |
222 ms |
15988 KB |
Output is correct |
12 |
Correct |
338 ms |
16008 KB |
Output is correct |
13 |
Correct |
259 ms |
15992 KB |
Output is correct |
14 |
Correct |
209 ms |
16000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
6244 KB |
Output is correct |
2 |
Correct |
41 ms |
7472 KB |
Output is correct |
3 |
Correct |
55 ms |
8432 KB |
Output is correct |
4 |
Correct |
173 ms |
15984 KB |
Output is correct |
5 |
Correct |
145 ms |
15968 KB |
Output is correct |
6 |
Correct |
231 ms |
16000 KB |
Output is correct |
7 |
Correct |
160 ms |
15988 KB |
Output is correct |
8 |
Correct |
177 ms |
15996 KB |
Output is correct |
9 |
Correct |
201 ms |
15988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
5096 KB |
Output is correct |
2 |
Correct |
21 ms |
6256 KB |
Output is correct |
3 |
Correct |
180 ms |
14192 KB |
Output is correct |
4 |
Correct |
243 ms |
16212 KB |
Output is correct |
5 |
Correct |
257 ms |
16220 KB |
Output is correct |
6 |
Correct |
246 ms |
16208 KB |
Output is correct |
7 |
Correct |
218 ms |
16224 KB |
Output is correct |
8 |
Correct |
241 ms |
16328 KB |
Output is correct |
9 |
Correct |
229 ms |
16236 KB |
Output is correct |
10 |
Correct |
250 ms |
16332 KB |
Output is correct |
11 |
Correct |
204 ms |
15992 KB |
Output is correct |
12 |
Correct |
267 ms |
16100 KB |
Output is correct |
13 |
Correct |
278 ms |
16004 KB |
Output is correct |
14 |
Correct |
283 ms |
16000 KB |
Output is correct |
15 |
Correct |
225 ms |
16220 KB |
Output is correct |
16 |
Correct |
250 ms |
16236 KB |
Output is correct |
17 |
Correct |
239 ms |
15984 KB |
Output is correct |
18 |
Correct |
208 ms |
15992 KB |
Output is correct |
19 |
Correct |
248 ms |
16220 KB |
Output is correct |
20 |
Correct |
243 ms |
15996 KB |
Output is correct |
21 |
Correct |
194 ms |
16932 KB |
Output is correct |
22 |
Correct |
214 ms |
16936 KB |
Output is correct |
23 |
Correct |
228 ms |
16828 KB |
Output is correct |
24 |
Correct |
231 ms |
16712 KB |
Output is correct |
25 |
Correct |
286 ms |
16156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
31 ms |
6296 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
28 ms |
6288 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |