#include "highway.h"
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
const int N = 150'010;
int len;
vector<pii> adj0[N];
vector<pii> adj1[N];
int n, m;
ll A, B;
ll ask_edge(bool def, vector<int> T)
{
vector<int> vec(m, def);
for (int e : T) {
vec[e] = !def;
}
return ask(vec);
}
ll ask_ver(vector<int> V, int l, int r)
{
vector<int> vec(m, 1);
Loop (i,0,n)
for (auto [_, e] : adj1[i])
vec[e] = 0;
Loop (i,l,r)
for (auto [_, e] : adj1[V[i]])
vec[e] = 1;
return ask(vec);
}
ll ask_ver(vector<int> V) { return ask_ver(V, 0, V.size()); }
int bin_search(vector<int> V)
{
int l = 0, r = V.size();
while (r - l > 1) {
int mid = (l+r)/2;
ll dis = ask_ver(V, mid, V.size());
if (dis == A*len)
r = mid;
else
l = mid;
}
return V[l];
}
bool vis[N];
void bfs(int rt0, int rt1, vector<int> &vrt0, vector<int> &vrt1, vector<int> &T)
{
vrt0 = {rt0}; vrt1 = {rt1};
vector<int> *ans[2] = {&vrt0, &vrt1};
vector<pii> vec = {{rt0,0},{rt1,1}};
vis[rt0] = vis[rt1] = 1;
for (int i = 0; i < vec.size(); ++i) {
auto [v, c] = vec[i];
for (auto [u, e] : adj0[v]) {
if (vis[u])
continue;
vis[u] = 1;
ans[c]->push_back(u);
vec.push_back({u,c});
T.push_back(e);
}
}
}
void find_pair(int _N, vector<int> _U, vector<int> _V, int _A, int _B)
{
n = _N; m = _U.size(); A = _A; B = _B;
Loop (e,0,m) {
int v = _V[e], u = _U[e];
adj0[v].push_back({u, e});
adj0[u].push_back({v, e});
}
len = ask_edge(0, {})/A;
vector<int> V1, V2;
{
int l = 0, r = m;
while (r - l > 1) {
int mid = (l+r)/2;
vector<int> vec(mid);
iota(vec.begin(), vec.end(), 0);
if (ask_edge(0, vec) != len*A)
r = mid;
else
l = mid;
}
vector<int> T = {l};
bfs(_U[l], _V[l], V1, V2, T);
for (int e : T) {
int v = _V[e], u = _U[e];
adj1[v].push_back({u, e});
adj1[u].push_back({v, e});
}
}
int s = bin_search(V1);
int t = bin_search(V2);
answer(s, t);
}
Compilation message
highway.cpp: In function 'void bfs(int, int, std::vector<int>&, std::vector<int>&, std::vector<int>&)':
highway.cpp:61:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for (int i = 0; i < vec.size(); ++i) {
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7248 KB |
Output is correct |
2 |
Correct |
5 ms |
7248 KB |
Output is correct |
3 |
Correct |
5 ms |
7248 KB |
Output is correct |
4 |
Correct |
5 ms |
7356 KB |
Output is correct |
5 |
Correct |
4 ms |
7360 KB |
Output is correct |
6 |
Correct |
4 ms |
7248 KB |
Output is correct |
7 |
Correct |
5 ms |
7376 KB |
Output is correct |
8 |
Correct |
4 ms |
7360 KB |
Output is correct |
9 |
Correct |
4 ms |
7360 KB |
Output is correct |
10 |
Correct |
4 ms |
7360 KB |
Output is correct |
11 |
Correct |
4 ms |
7248 KB |
Output is correct |
12 |
Correct |
4 ms |
7248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7376 KB |
Output is correct |
2 |
Correct |
24 ms |
8356 KB |
Output is correct |
3 |
Correct |
230 ms |
17276 KB |
Output is correct |
4 |
Correct |
294 ms |
17180 KB |
Output is correct |
5 |
Correct |
268 ms |
17340 KB |
Output is correct |
6 |
Correct |
197 ms |
17268 KB |
Output is correct |
7 |
Correct |
266 ms |
17208 KB |
Output is correct |
8 |
Correct |
360 ms |
17296 KB |
Output is correct |
9 |
Correct |
275 ms |
17172 KB |
Output is correct |
10 |
Correct |
231 ms |
17340 KB |
Output is correct |
11 |
Correct |
369 ms |
15840 KB |
Output is correct |
12 |
Correct |
286 ms |
16088 KB |
Output is correct |
13 |
Correct |
240 ms |
16172 KB |
Output is correct |
14 |
Correct |
262 ms |
15960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
8272 KB |
Output is correct |
2 |
Correct |
34 ms |
9132 KB |
Output is correct |
3 |
Correct |
52 ms |
10156 KB |
Output is correct |
4 |
Correct |
165 ms |
15804 KB |
Output is correct |
5 |
Correct |
152 ms |
15800 KB |
Output is correct |
6 |
Correct |
120 ms |
15952 KB |
Output is correct |
7 |
Correct |
166 ms |
16092 KB |
Output is correct |
8 |
Correct |
137 ms |
15832 KB |
Output is correct |
9 |
Correct |
133 ms |
16168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7376 KB |
Output is correct |
2 |
Correct |
26 ms |
8368 KB |
Output is correct |
3 |
Correct |
229 ms |
15136 KB |
Output is correct |
4 |
Correct |
246 ms |
17168 KB |
Output is correct |
5 |
Correct |
259 ms |
17224 KB |
Output is correct |
6 |
Correct |
296 ms |
17168 KB |
Output is correct |
7 |
Correct |
243 ms |
17180 KB |
Output is correct |
8 |
Correct |
216 ms |
17284 KB |
Output is correct |
9 |
Correct |
283 ms |
17172 KB |
Output is correct |
10 |
Correct |
392 ms |
17056 KB |
Output is correct |
11 |
Correct |
332 ms |
16164 KB |
Output is correct |
12 |
Correct |
293 ms |
16076 KB |
Output is correct |
13 |
Correct |
317 ms |
16216 KB |
Output is correct |
14 |
Correct |
274 ms |
15664 KB |
Output is correct |
15 |
Correct |
262 ms |
17164 KB |
Output is correct |
16 |
Correct |
292 ms |
17212 KB |
Output is correct |
17 |
Correct |
273 ms |
16200 KB |
Output is correct |
18 |
Correct |
248 ms |
16144 KB |
Output is correct |
19 |
Correct |
224 ms |
17188 KB |
Output is correct |
20 |
Correct |
235 ms |
16152 KB |
Output is correct |
21 |
Correct |
237 ms |
17480 KB |
Output is correct |
22 |
Correct |
212 ms |
17440 KB |
Output is correct |
23 |
Correct |
273 ms |
17244 KB |
Output is correct |
24 |
Correct |
257 ms |
17232 KB |
Output is correct |
25 |
Correct |
237 ms |
16168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
8484 KB |
Output is correct |
2 |
Correct |
27 ms |
8460 KB |
Output is correct |
3 |
Correct |
302 ms |
17632 KB |
Output is correct |
4 |
Correct |
391 ms |
17676 KB |
Output is correct |
5 |
Correct |
347 ms |
18524 KB |
Output is correct |
6 |
Correct |
432 ms |
18376 KB |
Output is correct |
7 |
Correct |
401 ms |
18256 KB |
Output is correct |
8 |
Correct |
375 ms |
18260 KB |
Output is correct |
9 |
Correct |
199 ms |
14504 KB |
Output is correct |
10 |
Correct |
157 ms |
14472 KB |
Output is correct |
11 |
Correct |
225 ms |
15516 KB |
Output is correct |
12 |
Correct |
322 ms |
17088 KB |
Output is correct |
13 |
Correct |
426 ms |
17828 KB |
Output is correct |
14 |
Correct |
364 ms |
18164 KB |
Output is correct |
15 |
Correct |
382 ms |
18200 KB |
Output is correct |
16 |
Correct |
248 ms |
15440 KB |
Output is correct |
17 |
Correct |
246 ms |
17532 KB |
Output is correct |
18 |
Correct |
333 ms |
17964 KB |
Output is correct |
19 |
Correct |
262 ms |
17816 KB |
Output is correct |
20 |
Correct |
207 ms |
17932 KB |
Output is correct |
21 |
Correct |
465 ms |
18524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
8404 KB |
Output is correct |
2 |
Correct |
21 ms |
8448 KB |
Output is correct |
3 |
Correct |
299 ms |
17120 KB |
Output is correct |
4 |
Correct |
372 ms |
17404 KB |
Output is correct |
5 |
Correct |
314 ms |
17480 KB |
Output is correct |
6 |
Correct |
427 ms |
18224 KB |
Output is correct |
7 |
Correct |
297 ms |
17556 KB |
Output is correct |
8 |
Correct |
344 ms |
17872 KB |
Output is correct |
9 |
Correct |
271 ms |
17560 KB |
Output is correct |
10 |
Correct |
385 ms |
18192 KB |
Output is correct |
11 |
Correct |
457 ms |
18324 KB |
Output is correct |
12 |
Correct |
376 ms |
18296 KB |
Output is correct |
13 |
Correct |
220 ms |
15480 KB |
Output is correct |
14 |
Correct |
207 ms |
14620 KB |
Output is correct |
15 |
Correct |
231 ms |
15452 KB |
Output is correct |
16 |
Correct |
218 ms |
14540 KB |
Output is correct |
17 |
Correct |
243 ms |
15592 KB |
Output is correct |
18 |
Correct |
210 ms |
14500 KB |
Output is correct |
19 |
Correct |
265 ms |
17016 KB |
Output is correct |
20 |
Correct |
344 ms |
17796 KB |
Output is correct |
21 |
Correct |
426 ms |
17992 KB |
Output is correct |
22 |
Correct |
410 ms |
18040 KB |
Output is correct |
23 |
Correct |
355 ms |
18188 KB |
Output is correct |
24 |
Correct |
387 ms |
18092 KB |
Output is correct |
25 |
Correct |
424 ms |
18324 KB |
Output is correct |
26 |
Correct |
462 ms |
18216 KB |
Output is correct |
27 |
Correct |
244 ms |
17704 KB |
Output is correct |
28 |
Correct |
293 ms |
17728 KB |
Output is correct |
29 |
Correct |
228 ms |
17996 KB |
Output is correct |
30 |
Correct |
193 ms |
17788 KB |
Output is correct |
31 |
Correct |
268 ms |
17788 KB |
Output is correct |
32 |
Correct |
294 ms |
17640 KB |
Output is correct |
33 |
Correct |
268 ms |
18140 KB |
Output is correct |
34 |
Correct |
298 ms |
17716 KB |
Output is correct |
35 |
Correct |
263 ms |
17636 KB |
Output is correct |
36 |
Correct |
318 ms |
17592 KB |
Output is correct |
37 |
Correct |
270 ms |
17936 KB |
Output is correct |
38 |
Correct |
187 ms |
17776 KB |
Output is correct |
39 |
Correct |
374 ms |
18552 KB |
Output is correct |
40 |
Correct |
402 ms |
18392 KB |
Output is correct |
41 |
Correct |
336 ms |
18548 KB |
Output is correct |
42 |
Correct |
329 ms |
18124 KB |
Output is correct |