#include "highway.h"
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
using i64 = long long;
using d64 = long double;
using pi = pair<int, int>;
using pli = pair<i64, i64>;
using ti = tuple<int, int, int>;
using tli = tuple<i64, i64, i64>;
#define iterall(cont) cont.begin(), cont.end()
#define prec(n) setprecision(n) << fixed
void find_pair(const int N, vector<int> U, vector<int> V, int A, int B) {
const int M = U.size();
i64 defaultDist = ask(vector<int>(M));
int dst = defaultDist / A;
int edgUsed;
{
int s = 0, e = M - 1;
while (s < e) {
int m = (s + e + 1) >> 1;
vector<int> q(M);
fill(q.begin(), q.begin() + m, 1);
i64 d = ask(q);
if (d == defaultDist)
s = m;
else
e = m - 1;
}
edgUsed = s;
}
int u = U[edgUsed];
int v = V[edgUsed];
vector<vector<pi>> graph(N);
for (int i = 0; i < M; i++) {
graph[U[i]].emplace_back(V[i], i);
graph[V[i]].emplace_back(U[i], i);
}
vector<int> vtyp(N), par(N);
vector<i64> distu(N, -1), distv(N, -1);
distu[u] = distv[v] = 0;
{
queue<int> que;
que.emplace(u);
while (!que.empty()) {
auto cur = que.front();
que.pop();
for (auto [t, _] : graph[cur]) {
if (distu[t] == -1) {
distu[t] = distu[cur] + 1;
par[t] = cur;
que.emplace(t);
}
}
}
}
{
queue<int> que;
que.emplace(v);
while (!que.empty()) {
auto cur = que.front();
que.pop();
for (auto [t, _] : graph[cur]) {
if (distv[t] == -1) {
distv[t] = distv[cur] + 1;
par[t] = cur;
que.emplace(t);
}
}
}
}
int us, vs;
for (int i = 0; i < N; i++) {
if (distv[i] > distu[i]) vtyp[i] = 1;
if (distu[i] > distv[i]) vtyp[i] = 2;
}
{
vector<int> hb;
for (int i = 0; i < N; i++)
if (vtyp[i] == 1) hb.emplace_back(i);
auto H = hb.size();
sort(iterall(hb), [&](int l, int r) {
return distu[l] < distu[r];
});
int s = 0, e = H - 1;
while (s < e) {
int m = (s + e + 1) >> 1;
vector<int> q(M);
vector<bool> c(N);
for (int i = m; i < H; i++) c[hb[i]] = true;
for (int i = 0; i < M; i++)
if (c[U[i]] || c[V[i]]) q[i] = 1;
i64 d = ask(q);
if (d == defaultDist)
e = m - 1;
else
s = m;
}
us = hb[s];
}
{
vector<int> hb;
for (int i = 0; i < N; i++)
if (vtyp[i] == 2) hb.emplace_back(i);
auto H = hb.size();
sort(iterall(hb), [&](int l, int r) {
return distv[l] < distv[r];
});
int s = 0, e = H - 1;
while (s < e) {
int m = (s + e + 1) >> 1;
vector<int> q(M);
vector<bool> c(N);
for (int i = m; i < H; i++) c[hb[i]] = true;
for (int i = 0; i < M; i++)
if (c[U[i]] || c[V[i]]) q[i] = 1;
i64 d = ask(q);
if (d == defaultDist)
e = m - 1;
else
s = m;
}
vs = hb[s];
}
answer(us, vs);
}
Compilation message
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:120:31: warning: comparison of integer expressions of different signedness: 'int' and 'long unsigned int' [-Wsign-compare]
120 | for (int i = m; i < H; i++) c[hb[i]] = true;
| ~~^~~
highway.cpp:151:31: warning: comparison of integer expressions of different signedness: 'int' and 'long unsigned int' [-Wsign-compare]
151 | for (int i = m; i < H; i++) c[hb[i]] = true;
| ~~^~~
highway.cpp:24:9: warning: unused variable 'dst' [-Wunused-variable]
24 | int dst = defaultDist / A;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
13 ms |
1528 KB |
Output is correct |
3 |
Correct |
168 ms |
10344 KB |
Output is correct |
4 |
Correct |
166 ms |
10412 KB |
Output is correct |
5 |
Correct |
182 ms |
10496 KB |
Output is correct |
6 |
Correct |
150 ms |
10260 KB |
Output is correct |
7 |
Correct |
182 ms |
10264 KB |
Output is correct |
8 |
Correct |
163 ms |
10272 KB |
Output is correct |
9 |
Correct |
214 ms |
10268 KB |
Output is correct |
10 |
Correct |
198 ms |
10264 KB |
Output is correct |
11 |
Correct |
198 ms |
9684 KB |
Output is correct |
12 |
Correct |
186 ms |
9636 KB |
Output is correct |
13 |
Correct |
229 ms |
9704 KB |
Output is correct |
14 |
Correct |
193 ms |
9688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
1400 KB |
Output is correct |
2 |
Correct |
23 ms |
2400 KB |
Output is correct |
3 |
Correct |
56 ms |
3396 KB |
Output is correct |
4 |
Correct |
164 ms |
9676 KB |
Output is correct |
5 |
Correct |
173 ms |
9696 KB |
Output is correct |
6 |
Correct |
177 ms |
9596 KB |
Output is correct |
7 |
Correct |
133 ms |
9732 KB |
Output is correct |
8 |
Correct |
128 ms |
9700 KB |
Output is correct |
9 |
Correct |
134 ms |
9620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
17 ms |
1404 KB |
Output is correct |
3 |
Correct |
117 ms |
8060 KB |
Output is correct |
4 |
Correct |
172 ms |
10264 KB |
Output is correct |
5 |
Correct |
198 ms |
10288 KB |
Output is correct |
6 |
Correct |
214 ms |
10264 KB |
Output is correct |
7 |
Correct |
178 ms |
10280 KB |
Output is correct |
8 |
Correct |
208 ms |
10264 KB |
Output is correct |
9 |
Correct |
184 ms |
10240 KB |
Output is correct |
10 |
Correct |
200 ms |
10256 KB |
Output is correct |
11 |
Correct |
229 ms |
9712 KB |
Output is correct |
12 |
Correct |
217 ms |
9656 KB |
Output is correct |
13 |
Correct |
239 ms |
9652 KB |
Output is correct |
14 |
Correct |
223 ms |
9704 KB |
Output is correct |
15 |
Correct |
200 ms |
10296 KB |
Output is correct |
16 |
Correct |
205 ms |
10296 KB |
Output is correct |
17 |
Correct |
202 ms |
9684 KB |
Output is correct |
18 |
Correct |
191 ms |
9700 KB |
Output is correct |
19 |
Correct |
150 ms |
10296 KB |
Output is correct |
20 |
Correct |
187 ms |
9688 KB |
Output is correct |
21 |
Correct |
166 ms |
10432 KB |
Output is correct |
22 |
Correct |
184 ms |
10528 KB |
Output is correct |
23 |
Correct |
197 ms |
10376 KB |
Output is correct |
24 |
Correct |
206 ms |
10292 KB |
Output is correct |
25 |
Correct |
172 ms |
9756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
1408 KB |
Output is correct |
2 |
Correct |
18 ms |
1536 KB |
Output is correct |
3 |
Correct |
182 ms |
10544 KB |
Output is correct |
4 |
Correct |
247 ms |
11088 KB |
Output is correct |
5 |
Correct |
306 ms |
11896 KB |
Output is correct |
6 |
Correct |
271 ms |
12096 KB |
Output is correct |
7 |
Correct |
271 ms |
12008 KB |
Output is correct |
8 |
Correct |
267 ms |
12040 KB |
Output is correct |
9 |
Correct |
248 ms |
7628 KB |
Output is correct |
10 |
Correct |
204 ms |
7976 KB |
Output is correct |
11 |
Correct |
271 ms |
8972 KB |
Output is correct |
12 |
Correct |
319 ms |
10568 KB |
Output is correct |
13 |
Correct |
326 ms |
11432 KB |
Output is correct |
14 |
Correct |
337 ms |
12024 KB |
Output is correct |
15 |
Correct |
319 ms |
12036 KB |
Output is correct |
16 |
Correct |
246 ms |
8684 KB |
Output is correct |
17 |
Correct |
154 ms |
10484 KB |
Output is correct |
18 |
Correct |
207 ms |
10808 KB |
Output is correct |
19 |
Correct |
156 ms |
10556 KB |
Output is correct |
20 |
Correct |
191 ms |
10768 KB |
Output is correct |
21 |
Correct |
274 ms |
11968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
1400 KB |
Output is correct |
2 |
Correct |
18 ms |
1528 KB |
Output is correct |
3 |
Correct |
266 ms |
10656 KB |
Output is correct |
4 |
Correct |
236 ms |
10880 KB |
Output is correct |
5 |
Correct |
209 ms |
11056 KB |
Output is correct |
6 |
Correct |
297 ms |
11976 KB |
Output is correct |
7 |
Correct |
181 ms |
10632 KB |
Output is correct |
8 |
Correct |
185 ms |
10956 KB |
Output is correct |
9 |
Correct |
227 ms |
11036 KB |
Output is correct |
10 |
Correct |
282 ms |
11992 KB |
Output is correct |
11 |
Correct |
297 ms |
11880 KB |
Output is correct |
12 |
Correct |
299 ms |
11924 KB |
Output is correct |
13 |
Correct |
206 ms |
9060 KB |
Output is correct |
14 |
Correct |
171 ms |
7884 KB |
Output is correct |
15 |
Correct |
195 ms |
9044 KB |
Output is correct |
16 |
Correct |
193 ms |
7964 KB |
Output is correct |
17 |
Correct |
206 ms |
9056 KB |
Output is correct |
18 |
Correct |
191 ms |
7920 KB |
Output is correct |
19 |
Correct |
280 ms |
10560 KB |
Output is correct |
20 |
Correct |
242 ms |
11516 KB |
Output is correct |
21 |
Correct |
263 ms |
12020 KB |
Output is correct |
22 |
Correct |
278 ms |
12000 KB |
Output is correct |
23 |
Correct |
329 ms |
11932 KB |
Output is correct |
24 |
Correct |
332 ms |
12032 KB |
Output is correct |
25 |
Correct |
261 ms |
12004 KB |
Output is correct |
26 |
Correct |
285 ms |
11992 KB |
Output is correct |
27 |
Correct |
176 ms |
10600 KB |
Output is correct |
28 |
Correct |
200 ms |
10504 KB |
Output is correct |
29 |
Correct |
190 ms |
10760 KB |
Output is correct |
30 |
Correct |
171 ms |
10640 KB |
Output is correct |
31 |
Correct |
159 ms |
10600 KB |
Output is correct |
32 |
Correct |
212 ms |
10496 KB |
Output is correct |
33 |
Correct |
213 ms |
10784 KB |
Output is correct |
34 |
Correct |
172 ms |
10528 KB |
Output is correct |
35 |
Correct |
180 ms |
10556 KB |
Output is correct |
36 |
Correct |
167 ms |
10452 KB |
Output is correct |
37 |
Correct |
169 ms |
10728 KB |
Output is correct |
38 |
Correct |
168 ms |
10688 KB |
Output is correct |
39 |
Correct |
283 ms |
12104 KB |
Output is correct |
40 |
Correct |
276 ms |
11868 KB |
Output is correct |
41 |
Correct |
266 ms |
11912 KB |
Output is correct |
42 |
Correct |
276 ms |
12032 KB |
Output is correct |