#include "highway.h"
#include <vector>
#include <queue>
#include <utility>
#include <iostream>
#define MAXN 90005
#define MAXE 130005
using namespace std;
queue <int> Q;
vector <pair<int,int> > adj[MAXN];
bool color[MAXN], vis[MAXN], inTree[MAXE];
int eid[MAXN];
vector <int> dist[2]; //ordered by dist
void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
int M = U.size();
vector<int> w(M);
for (int i = 0; i < M; ++i) {
w[i] = 0;
}
long long base = ask(w);
int lo = -1, hi = M-1; //find edge on shortest path
while (lo + 1 != hi) {
int mid = (lo + hi) >> 1;
for (int i=0; i < M; i++) {
w[i] = i <= mid;
}
if (ask(w) != base) {hi = mid;}
else {lo = mid;}
}
Q.push(U[hi]);
Q.push(V[hi]);
color[V[hi]] = true;
inTree[hi] = true;
vis[U[hi]] = vis[V[hi]] = true;
for (int i=0; i<M; i++) {
adj[U[i]].push_back({V[i], i});
adj[V[i]].push_back({U[i], i});
}
while (Q.size()) {
int u = Q.front();
Q.pop();
dist[color[u]].push_back(u);
for (auto v: adj[u]) {
if (vis[v.first]) {continue;}
vis[v.first] = true;
inTree[v.second] = true;
eid[v.first] = v.second;
color[v.first] = color[u];
Q.push(v.first);
}
}
lo = 0, hi = dist[0].size()-1;
while (lo != hi) {
int mid = (lo + hi + 1) >> 1;
for (int i=0; i<M; i++) {
w[i] = !inTree[i];
}
for (int i=dist[0].size()-1; i>=mid; i--) {
w[eid[dist[0][i]]]=1;
}
if (ask(w) == base) {hi = mid-1;}
else {lo = mid;}
}
int retA = dist[0][lo];
lo = 0, hi = dist[1].size()-1;
while (lo != hi) {
int mid = (lo + hi + 1) >> 1;
for (int i=0; i<M; i++) {
w[i] = !inTree[i];
}
for (int i=dist[1].size()-1; i>=mid; i--) {
w[eid[dist[1][i]]]=1;
}
if (ask(w) == base) {hi = mid-1;}
else {lo = mid;}
}
int retB = dist[1][lo];
answer(retA, retB);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2496 KB |
Output is correct |
2 |
Correct |
6 ms |
2432 KB |
Output is correct |
3 |
Correct |
6 ms |
2432 KB |
Output is correct |
4 |
Correct |
6 ms |
2480 KB |
Output is correct |
5 |
Correct |
6 ms |
2432 KB |
Output is correct |
6 |
Correct |
6 ms |
2432 KB |
Output is correct |
7 |
Correct |
6 ms |
2584 KB |
Output is correct |
8 |
Correct |
6 ms |
2432 KB |
Output is correct |
9 |
Correct |
6 ms |
2480 KB |
Output is correct |
10 |
Correct |
6 ms |
2536 KB |
Output is correct |
11 |
Correct |
6 ms |
2432 KB |
Output is correct |
12 |
Correct |
7 ms |
2432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2536 KB |
Output is correct |
2 |
Correct |
22 ms |
3236 KB |
Output is correct |
3 |
Correct |
169 ms |
8900 KB |
Output is correct |
4 |
Correct |
176 ms |
8932 KB |
Output is correct |
5 |
Correct |
169 ms |
8928 KB |
Output is correct |
6 |
Correct |
153 ms |
8904 KB |
Output is correct |
7 |
Correct |
157 ms |
8872 KB |
Output is correct |
8 |
Correct |
179 ms |
8928 KB |
Output is correct |
9 |
Correct |
176 ms |
8884 KB |
Output is correct |
10 |
Correct |
152 ms |
8892 KB |
Output is correct |
11 |
Correct |
185 ms |
8252 KB |
Output is correct |
12 |
Correct |
176 ms |
8360 KB |
Output is correct |
13 |
Correct |
179 ms |
8348 KB |
Output is correct |
14 |
Correct |
165 ms |
8400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
3168 KB |
Output is correct |
2 |
Correct |
29 ms |
3784 KB |
Output is correct |
3 |
Correct |
37 ms |
4480 KB |
Output is correct |
4 |
Correct |
130 ms |
8276 KB |
Output is correct |
5 |
Correct |
139 ms |
8352 KB |
Output is correct |
6 |
Correct |
135 ms |
8304 KB |
Output is correct |
7 |
Correct |
129 ms |
8224 KB |
Output is correct |
8 |
Correct |
129 ms |
8300 KB |
Output is correct |
9 |
Correct |
127 ms |
8336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2560 KB |
Output is correct |
2 |
Correct |
19 ms |
3200 KB |
Output is correct |
3 |
Correct |
113 ms |
7676 KB |
Output is correct |
4 |
Correct |
149 ms |
8900 KB |
Output is correct |
5 |
Correct |
172 ms |
8852 KB |
Output is correct |
6 |
Correct |
159 ms |
8824 KB |
Output is correct |
7 |
Correct |
158 ms |
8860 KB |
Output is correct |
8 |
Correct |
184 ms |
8864 KB |
Output is correct |
9 |
Correct |
192 ms |
8852 KB |
Output is correct |
10 |
Correct |
175 ms |
8940 KB |
Output is correct |
11 |
Correct |
167 ms |
8316 KB |
Output is correct |
12 |
Correct |
202 ms |
8488 KB |
Output is correct |
13 |
Correct |
183 ms |
8352 KB |
Output is correct |
14 |
Correct |
178 ms |
8228 KB |
Output is correct |
15 |
Correct |
213 ms |
8956 KB |
Output is correct |
16 |
Correct |
161 ms |
9012 KB |
Output is correct |
17 |
Correct |
169 ms |
8364 KB |
Output is correct |
18 |
Correct |
170 ms |
8368 KB |
Output is correct |
19 |
Correct |
158 ms |
8936 KB |
Output is correct |
20 |
Correct |
207 ms |
8352 KB |
Output is correct |
21 |
Correct |
142 ms |
9660 KB |
Output is correct |
22 |
Correct |
143 ms |
9756 KB |
Output is correct |
23 |
Correct |
163 ms |
9212 KB |
Output is correct |
24 |
Correct |
183 ms |
9128 KB |
Output is correct |
25 |
Correct |
186 ms |
8532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
3200 KB |
Output is correct |
2 |
Correct |
25 ms |
3328 KB |
Output is correct |
3 |
Correct |
169 ms |
9276 KB |
Output is correct |
4 |
Correct |
254 ms |
9904 KB |
Output is correct |
5 |
Correct |
282 ms |
10836 KB |
Output is correct |
6 |
Correct |
242 ms |
10588 KB |
Output is correct |
7 |
Correct |
280 ms |
10640 KB |
Output is correct |
8 |
Correct |
277 ms |
10632 KB |
Output is correct |
9 |
Correct |
167 ms |
8624 KB |
Output is correct |
10 |
Correct |
222 ms |
9288 KB |
Output is correct |
11 |
Correct |
177 ms |
9448 KB |
Output is correct |
12 |
Correct |
267 ms |
10340 KB |
Output is correct |
13 |
Correct |
243 ms |
10648 KB |
Output is correct |
14 |
Correct |
249 ms |
10656 KB |
Output is correct |
15 |
Correct |
249 ms |
10588 KB |
Output is correct |
16 |
Correct |
215 ms |
9536 KB |
Output is correct |
17 |
Correct |
191 ms |
9448 KB |
Output is correct |
18 |
Correct |
164 ms |
9640 KB |
Output is correct |
19 |
Correct |
174 ms |
9572 KB |
Output is correct |
20 |
Correct |
160 ms |
9688 KB |
Output is correct |
21 |
Correct |
270 ms |
10736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
3200 KB |
Output is correct |
2 |
Correct |
21 ms |
3320 KB |
Output is correct |
3 |
Correct |
235 ms |
9320 KB |
Output is correct |
4 |
Correct |
255 ms |
9428 KB |
Output is correct |
5 |
Correct |
217 ms |
9636 KB |
Output is correct |
6 |
Correct |
288 ms |
10664 KB |
Output is correct |
7 |
Correct |
205 ms |
9264 KB |
Output is correct |
8 |
Correct |
190 ms |
9568 KB |
Output is correct |
9 |
Correct |
205 ms |
9656 KB |
Output is correct |
10 |
Correct |
235 ms |
10660 KB |
Output is correct |
11 |
Correct |
269 ms |
10636 KB |
Output is correct |
12 |
Correct |
295 ms |
10632 KB |
Output is correct |
13 |
Correct |
230 ms |
9552 KB |
Output is correct |
14 |
Correct |
221 ms |
9132 KB |
Output is correct |
15 |
Correct |
172 ms |
9460 KB |
Output is correct |
16 |
Correct |
169 ms |
9072 KB |
Output is correct |
17 |
Correct |
175 ms |
9452 KB |
Output is correct |
18 |
Correct |
164 ms |
9212 KB |
Output is correct |
19 |
Correct |
234 ms |
10244 KB |
Output is correct |
20 |
Correct |
277 ms |
10512 KB |
Output is correct |
21 |
Correct |
252 ms |
10676 KB |
Output is correct |
22 |
Correct |
240 ms |
10688 KB |
Output is correct |
23 |
Correct |
254 ms |
10608 KB |
Output is correct |
24 |
Correct |
226 ms |
10740 KB |
Output is correct |
25 |
Correct |
246 ms |
10800 KB |
Output is correct |
26 |
Correct |
231 ms |
10844 KB |
Output is correct |
27 |
Correct |
133 ms |
9528 KB |
Output is correct |
28 |
Correct |
159 ms |
9480 KB |
Output is correct |
29 |
Correct |
149 ms |
9772 KB |
Output is correct |
30 |
Correct |
139 ms |
9472 KB |
Output is correct |
31 |
Correct |
149 ms |
9576 KB |
Output is correct |
32 |
Correct |
165 ms |
9484 KB |
Output is correct |
33 |
Correct |
153 ms |
9740 KB |
Output is correct |
34 |
Correct |
164 ms |
9516 KB |
Output is correct |
35 |
Correct |
154 ms |
9588 KB |
Output is correct |
36 |
Correct |
157 ms |
9484 KB |
Output is correct |
37 |
Correct |
164 ms |
9700 KB |
Output is correct |
38 |
Correct |
138 ms |
9444 KB |
Output is correct |
39 |
Correct |
227 ms |
10844 KB |
Output is correct |
40 |
Correct |
251 ms |
10872 KB |
Output is correct |
41 |
Correct |
227 ms |
10648 KB |
Output is correct |
42 |
Correct |
237 ms |
10800 KB |
Output is correct |