#include "highway.h"
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
int N, M, U[1 << 18], V[1 << 18], dist[1 << 18], par[1 << 18], paredge[1 << 18];
vector<pair<int, int>> G[1 << 18]; bool anti[1 << 18];
void find_pair(int NN, vector<int> UU, vector<int> VV, int A, int B) {
// ----------------------------- Step 0: Input ---------------------------
N = NN; M = UU.size();
for (int i = 0; i < M; i++) { U[i] = UU[i]; V[i] = VV[i]; }
// -------------------------- Step 1: Get All-A --------------------------
vector<int> W(M, 0);
long long BASE = ask(W), DIST = BASE / A;
// ---------------------- Step 2: The Minimum Vertex ---------------------
int c1 = 0;
for (int i = 16; i >= 0; i--) {
for (int j = 0; j < M; j++) {
if (min(U[j], V[j]) >= c1 + (1 << i)) W[j] = 0;
else W[j] = 1;
}
long long p1 = ask(W);
if (p1 == BASE) { c1 += (1 << i); }
}
// -------------------------- Step 3: Make Tree --------------------------
for (int i = 0; i < M; i++) {
if (min(U[i], V[i]) < c1) continue;
G[U[i]].push_back(make_pair(V[i], i));
G[V[i]].push_back(make_pair(U[i], i));
}
for (int i = 0; i < N; i++) dist[i] = (1 << 30);
queue<int> que; que.push(c1); dist[c1] = 0;
while (!que.empty()) {
int pos1 = que.front(); que.pop();
for (int i = 0; i < G[pos1].size(); i++) {
int to = G[pos1][i].first;
if (dist[to] > dist[pos1] + 1) {
dist[to] = dist[pos1] + 1;
que.push(to);
}
}
}
for (int i = c1 + 1; i < N; i++) {
for (int j = 0; j < G[i].size(); j++) {
int to = G[i][j].first;
if (dist[i] > dist[to]) { par[i] = to; paredge[i] = G[i][j].second; break; }
}
}
// ---------------------------- 4. Find T --------------------------------
vector<pair<int, int>> V;
for (int i = c1 + 1; i < N; i++) {
if (dist[i] == (1 << 30)) continue;
V.push_back(make_pair(dist[i], i));
}
sort(V.begin(), V.end());
//for (int i = 0; i < V.size(); i++) cout << "V[" << i << "] = " << V[i].second << endl;
int c2 = 0;
for (int i = 16; i >= 0; i--) {
for (int j = 0; j < W.size(); j++) W[j] = 1;
for (int j = 0; j < c2 + (1 << i); j++) {
if (j >= V.size()) break;
W[paredge[V[j].second]] = 0;
}
long long p2 = ask(W);
if (p2 != BASE) c2 += (1 << i);
}
// --------------------- 5. Find the candidate of S ----------------------
long long T = V[c2].second, cand_dst = DIST - dist[T];
if (cand_dst == 0) {
answer(T, c1);
return;
}
int cx = T; anti[cx] = true;
while (true) {
cx = par[cx];
anti[cx] = true;
if (cx == c1) break;
}
vector<int> V2;
for (int i = c1 + 1; i < N; i++) {
if (dist[i] == cand_dst && anti[i] == false) V2.push_back(i);
}
// ----------------------------- 6. Find S --------------------------------
int c3 = 0;
for (int i = 16; i >= 0; i--) {
for (int j = 0; j < W.size(); j++) W[j] = 1;
for (int j = c1 + 1; j < N; j++) W[paredge[j]] = 0;
for (int j = 0; j < c3 + (1 << i); j++) {
if (j >= V2.size()) break;
W[paredge[V2[j]]] = 1;
}
long long p3 = ask(W);
if (p3 == BASE) c3 += (1 << i);
}
long long S = V2[c3];
answer(S, T);
return;
}
Compilation message
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:44:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < G[pos1].size(); i++) {
~~^~~~~~~~~~~~~~~~
highway.cpp:54:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < G[i].size(); j++) {
~~^~~~~~~~~~~~~
highway.cpp:72:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < W.size(); j++) W[j] = 1;
~~^~~~~~~~~~
highway.cpp:74:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (j >= V.size()) break;
~~^~~~~~~~~~~
highway.cpp:103:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < W.size(); j++) W[j] = 1;
~~^~~~~~~~~~
highway.cpp:107:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (j >= V2.size()) break;
~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
6500 KB |
Output is correct |
2 |
Correct |
7 ms |
6392 KB |
Output is correct |
3 |
Correct |
8 ms |
6580 KB |
Output is correct |
4 |
Correct |
8 ms |
6584 KB |
Output is correct |
5 |
Correct |
8 ms |
6392 KB |
Output is correct |
6 |
Correct |
8 ms |
6392 KB |
Output is correct |
7 |
Correct |
8 ms |
6392 KB |
Output is correct |
8 |
Correct |
8 ms |
6444 KB |
Output is correct |
9 |
Correct |
8 ms |
6392 KB |
Output is correct |
10 |
Correct |
7 ms |
6500 KB |
Output is correct |
11 |
Correct |
8 ms |
6500 KB |
Output is correct |
12 |
Correct |
8 ms |
6500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
6520 KB |
Output is correct |
2 |
Correct |
45 ms |
7452 KB |
Output is correct |
3 |
Correct |
224 ms |
14504 KB |
Output is correct |
4 |
Correct |
222 ms |
14508 KB |
Output is correct |
5 |
Correct |
218 ms |
14540 KB |
Output is correct |
6 |
Correct |
226 ms |
14496 KB |
Output is correct |
7 |
Correct |
216 ms |
14508 KB |
Output is correct |
8 |
Correct |
207 ms |
14520 KB |
Output is correct |
9 |
Correct |
214 ms |
14524 KB |
Output is correct |
10 |
Correct |
222 ms |
14508 KB |
Output is correct |
11 |
Correct |
218 ms |
14036 KB |
Output is correct |
12 |
Correct |
226 ms |
13972 KB |
Output is correct |
13 |
Correct |
231 ms |
13976 KB |
Output is correct |
14 |
Correct |
256 ms |
13936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
7336 KB |
Output is correct |
2 |
Correct |
45 ms |
8056 KB |
Output is correct |
3 |
Correct |
48 ms |
7688 KB |
Output is correct |
4 |
Correct |
175 ms |
12092 KB |
Output is correct |
5 |
Correct |
167 ms |
12160 KB |
Output is correct |
6 |
Correct |
177 ms |
13324 KB |
Output is correct |
7 |
Correct |
143 ms |
9648 KB |
Output is correct |
8 |
Correct |
162 ms |
12460 KB |
Output is correct |
9 |
Correct |
149 ms |
10628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
6568 KB |
Output is correct |
2 |
Correct |
29 ms |
7452 KB |
Output is correct |
3 |
Correct |
162 ms |
12140 KB |
Output is correct |
4 |
Correct |
238 ms |
12992 KB |
Output is correct |
5 |
Correct |
231 ms |
13880 KB |
Output is correct |
6 |
Correct |
190 ms |
12524 KB |
Output is correct |
7 |
Correct |
202 ms |
13512 KB |
Output is correct |
8 |
Correct |
224 ms |
13136 KB |
Output is correct |
9 |
Correct |
278 ms |
14332 KB |
Output is correct |
10 |
Correct |
212 ms |
14464 KB |
Output is correct |
11 |
Correct |
235 ms |
13296 KB |
Output is correct |
12 |
Correct |
253 ms |
13964 KB |
Output is correct |
13 |
Correct |
235 ms |
13964 KB |
Output is correct |
14 |
Correct |
253 ms |
13580 KB |
Output is correct |
15 |
Correct |
220 ms |
13896 KB |
Output is correct |
16 |
Correct |
211 ms |
12956 KB |
Output is correct |
17 |
Correct |
247 ms |
13604 KB |
Output is correct |
18 |
Correct |
219 ms |
13324 KB |
Output is correct |
19 |
Correct |
165 ms |
12332 KB |
Output is correct |
20 |
Correct |
201 ms |
13096 KB |
Output is correct |
21 |
Correct |
230 ms |
13436 KB |
Output is correct |
22 |
Correct |
183 ms |
12336 KB |
Output is correct |
23 |
Correct |
218 ms |
15100 KB |
Output is correct |
24 |
Correct |
266 ms |
15004 KB |
Output is correct |
25 |
Correct |
266 ms |
14088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
7528 KB |
Output is correct |
2 |
Correct |
29 ms |
7576 KB |
Output is correct |
3 |
Correct |
231 ms |
14752 KB |
Output is correct |
4 |
Correct |
240 ms |
14652 KB |
Output is correct |
5 |
Correct |
324 ms |
16040 KB |
Output is correct |
6 |
Correct |
288 ms |
15564 KB |
Output is correct |
7 |
Correct |
332 ms |
15948 KB |
Output is correct |
8 |
Correct |
289 ms |
16200 KB |
Output is correct |
9 |
Correct |
202 ms |
11404 KB |
Output is correct |
10 |
Correct |
195 ms |
11376 KB |
Output is correct |
11 |
Correct |
229 ms |
10804 KB |
Output is correct |
12 |
Correct |
296 ms |
14556 KB |
Output is correct |
13 |
Correct |
307 ms |
16208 KB |
Output is correct |
14 |
Correct |
323 ms |
16036 KB |
Output is correct |
15 |
Correct |
328 ms |
16032 KB |
Output is correct |
16 |
Correct |
293 ms |
14876 KB |
Output is correct |
17 |
Correct |
220 ms |
14860 KB |
Output is correct |
18 |
Correct |
225 ms |
14400 KB |
Output is correct |
19 |
Correct |
235 ms |
15012 KB |
Output is correct |
20 |
Correct |
216 ms |
13888 KB |
Output is correct |
21 |
Correct |
319 ms |
16636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
32 ms |
7436 KB |
Output is partially correct |
2 |
Partially correct |
30 ms |
7516 KB |
Output is partially correct |
3 |
Partially correct |
250 ms |
14364 KB |
Output is partially correct |
4 |
Partially correct |
253 ms |
14788 KB |
Output is partially correct |
5 |
Partially correct |
263 ms |
14484 KB |
Output is partially correct |
6 |
Partially correct |
327 ms |
16336 KB |
Output is partially correct |
7 |
Partially correct |
244 ms |
14544 KB |
Output is partially correct |
8 |
Correct |
228 ms |
15152 KB |
Output is correct |
9 |
Correct |
238 ms |
15512 KB |
Output is correct |
10 |
Partially correct |
337 ms |
16576 KB |
Output is partially correct |
11 |
Partially correct |
288 ms |
15796 KB |
Output is partially correct |
12 |
Partially correct |
336 ms |
16656 KB |
Output is partially correct |
13 |
Correct |
225 ms |
11392 KB |
Output is correct |
14 |
Correct |
270 ms |
14264 KB |
Output is correct |
15 |
Correct |
259 ms |
12908 KB |
Output is correct |
16 |
Correct |
241 ms |
12444 KB |
Output is correct |
17 |
Correct |
208 ms |
10652 KB |
Output is correct |
18 |
Correct |
247 ms |
12964 KB |
Output is correct |
19 |
Partially correct |
305 ms |
15136 KB |
Output is partially correct |
20 |
Partially correct |
308 ms |
15788 KB |
Output is partially correct |
21 |
Partially correct |
285 ms |
15540 KB |
Output is partially correct |
22 |
Partially correct |
304 ms |
15344 KB |
Output is partially correct |
23 |
Partially correct |
330 ms |
16412 KB |
Output is partially correct |
24 |
Partially correct |
305 ms |
16124 KB |
Output is partially correct |
25 |
Partially correct |
277 ms |
13632 KB |
Output is partially correct |
26 |
Partially correct |
324 ms |
16592 KB |
Output is partially correct |
27 |
Partially correct |
207 ms |
13772 KB |
Output is partially correct |
28 |
Correct |
184 ms |
13792 KB |
Output is correct |
29 |
Partially correct |
243 ms |
13584 KB |
Output is partially correct |
30 |
Partially correct |
207 ms |
12712 KB |
Output is partially correct |
31 |
Partially correct |
215 ms |
14380 KB |
Output is partially correct |
32 |
Partially correct |
225 ms |
13348 KB |
Output is partially correct |
33 |
Partially correct |
206 ms |
14344 KB |
Output is partially correct |
34 |
Correct |
246 ms |
14912 KB |
Output is correct |
35 |
Partially correct |
213 ms |
15012 KB |
Output is partially correct |
36 |
Partially correct |
274 ms |
13716 KB |
Output is partially correct |
37 |
Partially correct |
230 ms |
13964 KB |
Output is partially correct |
38 |
Partially correct |
223 ms |
13000 KB |
Output is partially correct |
39 |
Partially correct |
335 ms |
16708 KB |
Output is partially correct |
40 |
Partially correct |
333 ms |
16644 KB |
Output is partially correct |
41 |
Partially correct |
352 ms |
16584 KB |
Output is partially correct |
42 |
Partially correct |
302 ms |
16608 KB |
Output is partially correct |