#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> graph[90000], ord[2];
bool visited[90000];
int ans[2];
void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
for (int i = 0; i < N; i++) {
graph[i].clear();
visited[i] = false;
}
ord[0].clear(); ord[1].clear();
int M = int(U.size());
for (int i = 0; i < M; i++) {
graph[U[i]].push_back({V[i], i});
graph[V[i]].push_back({U[i], i});
}
vector<int> W(M, 0);
long long path_len = ask(W) / A;
int l = 0, r = M - 1;
while (l != r) {
int mid = (l + r) / 2;
fill(W.begin(), W.end(), 0);
for (int i = 0; i <= mid; i++) W[i] = 1;
long long res = ask(W);
if (res == path_len * A) l = mid + 1;
else r = mid;
}
int m_edge = l, uu = U[l], vv = V[l];
visited[uu] = visited[vv] = true;
queue<pair<int, int>> q;
q.push({uu, 0}); q.push({vv, 1});
ord[0].push_back({uu, -1}); ord[1].push_back({vv, -1});
while (q.size()) {
int curr, sub;
tie(curr, sub) = q.front();
q.pop();
for (pair<int, int> i : graph[curr]) {
if (!visited[i.first] && i.second > m_edge) {
visited[i.first] = true;
ord[sub].push_back(i);
q.push({i.first, sub});
}
}
}
for (int s = 0; s < 2; s++) {
l = 0, r = ord[s].size() - 1;
while (l != r) {
int mid = (l + r) / 2;
fill(W.begin(), W.end(), 1);
W[m_edge] = 0;
for (pair<int, int> i : ord[1 - s]) if (i.second != -1) W[i.second] = 0;
for (int i = 1; i <= mid; i++) W[ord[s][i].second] = 0;
long long dist = ask(W);
if (dist == path_len * A) r = mid;
else l = mid + 1;
}
ans[s] = ord[s][l].first;
}
answer(ans[0], ans[1]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2432 KB |
Output is correct |
2 |
Correct |
2 ms |
2432 KB |
Output is correct |
3 |
Correct |
2 ms |
2432 KB |
Output is correct |
4 |
Correct |
2 ms |
2432 KB |
Output is correct |
5 |
Correct |
2 ms |
2432 KB |
Output is correct |
6 |
Correct |
2 ms |
2432 KB |
Output is correct |
7 |
Correct |
2 ms |
2432 KB |
Output is correct |
8 |
Correct |
2 ms |
2492 KB |
Output is correct |
9 |
Correct |
2 ms |
2432 KB |
Output is correct |
10 |
Correct |
2 ms |
2432 KB |
Output is correct |
11 |
Correct |
3 ms |
2464 KB |
Output is correct |
12 |
Correct |
2 ms |
2496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2560 KB |
Output is correct |
2 |
Correct |
15 ms |
3196 KB |
Output is correct |
3 |
Correct |
193 ms |
8980 KB |
Output is correct |
4 |
Correct |
207 ms |
8864 KB |
Output is correct |
5 |
Correct |
203 ms |
8868 KB |
Output is correct |
6 |
Correct |
131 ms |
8336 KB |
Output is correct |
7 |
Correct |
143 ms |
8344 KB |
Output is correct |
8 |
Correct |
142 ms |
8852 KB |
Output is correct |
9 |
Correct |
130 ms |
8336 KB |
Output is correct |
10 |
Correct |
147 ms |
8408 KB |
Output is correct |
11 |
Correct |
131 ms |
7392 KB |
Output is correct |
12 |
Correct |
159 ms |
7940 KB |
Output is correct |
13 |
Correct |
142 ms |
8308 KB |
Output is correct |
14 |
Correct |
181 ms |
8424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
3276 KB |
Output is correct |
2 |
Correct |
27 ms |
3788 KB |
Output is correct |
3 |
Correct |
37 ms |
4040 KB |
Output is correct |
4 |
Correct |
110 ms |
7800 KB |
Output is correct |
5 |
Correct |
112 ms |
7796 KB |
Output is correct |
6 |
Correct |
134 ms |
8296 KB |
Output is correct |
7 |
Correct |
110 ms |
7280 KB |
Output is correct |
8 |
Correct |
112 ms |
7784 KB |
Output is correct |
9 |
Correct |
110 ms |
7560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2560 KB |
Output is correct |
2 |
Correct |
16 ms |
3072 KB |
Output is correct |
3 |
Correct |
107 ms |
7688 KB |
Output is correct |
4 |
Correct |
141 ms |
8968 KB |
Output is correct |
5 |
Correct |
117 ms |
7740 KB |
Output is correct |
6 |
Correct |
132 ms |
7728 KB |
Output is correct |
7 |
Correct |
137 ms |
8340 KB |
Output is correct |
8 |
Correct |
125 ms |
7844 KB |
Output is correct |
9 |
Correct |
203 ms |
8868 KB |
Output is correct |
10 |
Correct |
158 ms |
8360 KB |
Output is correct |
11 |
Correct |
173 ms |
8328 KB |
Output is correct |
12 |
Correct |
161 ms |
7900 KB |
Output is correct |
13 |
Correct |
141 ms |
7920 KB |
Output is correct |
14 |
Correct |
134 ms |
7436 KB |
Output is correct |
15 |
Correct |
145 ms |
7776 KB |
Output is correct |
16 |
Correct |
120 ms |
7780 KB |
Output is correct |
17 |
Correct |
200 ms |
8312 KB |
Output is correct |
18 |
Correct |
150 ms |
8340 KB |
Output is correct |
19 |
Correct |
129 ms |
7900 KB |
Output is correct |
20 |
Correct |
158 ms |
7224 KB |
Output is correct |
21 |
Correct |
181 ms |
8840 KB |
Output is correct |
22 |
Correct |
112 ms |
8340 KB |
Output is correct |
23 |
Correct |
133 ms |
9184 KB |
Output is correct |
24 |
Correct |
139 ms |
9156 KB |
Output is correct |
25 |
Correct |
159 ms |
8516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
3244 KB |
Output is correct |
2 |
Correct |
23 ms |
3368 KB |
Output is correct |
3 |
Correct |
233 ms |
9304 KB |
Output is correct |
4 |
Correct |
242 ms |
9460 KB |
Output is correct |
5 |
Correct |
261 ms |
10280 KB |
Output is correct |
6 |
Correct |
221 ms |
10404 KB |
Output is correct |
7 |
Correct |
233 ms |
10344 KB |
Output is correct |
8 |
Correct |
256 ms |
10656 KB |
Output is correct |
9 |
Correct |
184 ms |
7944 KB |
Output is correct |
10 |
Correct |
227 ms |
8896 KB |
Output is correct |
11 |
Correct |
253 ms |
9180 KB |
Output is correct |
12 |
Correct |
227 ms |
10176 KB |
Output is correct |
13 |
Correct |
240 ms |
10360 KB |
Output is correct |
14 |
Correct |
234 ms |
10404 KB |
Output is correct |
15 |
Correct |
284 ms |
10772 KB |
Output is correct |
16 |
Correct |
177 ms |
9428 KB |
Output is correct |
17 |
Correct |
139 ms |
8896 KB |
Output is correct |
18 |
Correct |
173 ms |
8400 KB |
Output is correct |
19 |
Correct |
182 ms |
9700 KB |
Output is correct |
20 |
Correct |
182 ms |
8580 KB |
Output is correct |
21 |
Correct |
209 ms |
10812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
3192 KB |
Output is correct |
2 |
Correct |
20 ms |
3320 KB |
Output is correct |
3 |
Correct |
181 ms |
9152 KB |
Output is correct |
4 |
Correct |
221 ms |
9244 KB |
Output is correct |
5 |
Correct |
185 ms |
9444 KB |
Output is correct |
6 |
Correct |
212 ms |
10676 KB |
Output is correct |
7 |
Correct |
155 ms |
9248 KB |
Output is correct |
8 |
Correct |
230 ms |
9568 KB |
Output is correct |
9 |
Correct |
241 ms |
9416 KB |
Output is correct |
10 |
Correct |
220 ms |
10400 KB |
Output is correct |
11 |
Correct |
218 ms |
10488 KB |
Output is correct |
12 |
Correct |
217 ms |
10544 KB |
Output is correct |
13 |
Correct |
158 ms |
8572 KB |
Output is correct |
14 |
Correct |
160 ms |
8584 KB |
Output is correct |
15 |
Correct |
185 ms |
9512 KB |
Output is correct |
16 |
Correct |
158 ms |
8880 KB |
Output is correct |
17 |
Correct |
178 ms |
9172 KB |
Output is correct |
18 |
Correct |
180 ms |
8964 KB |
Output is correct |
19 |
Correct |
210 ms |
10288 KB |
Output is correct |
20 |
Correct |
216 ms |
10796 KB |
Output is correct |
21 |
Correct |
228 ms |
10404 KB |
Output is correct |
22 |
Correct |
260 ms |
10500 KB |
Output is correct |
23 |
Correct |
236 ms |
10620 KB |
Output is correct |
24 |
Correct |
227 ms |
10576 KB |
Output is correct |
25 |
Correct |
214 ms |
10760 KB |
Output is correct |
26 |
Correct |
213 ms |
10716 KB |
Output is correct |
27 |
Correct |
132 ms |
8780 KB |
Output is correct |
28 |
Correct |
135 ms |
9672 KB |
Output is correct |
29 |
Correct |
123 ms |
9828 KB |
Output is correct |
30 |
Correct |
140 ms |
9572 KB |
Output is correct |
31 |
Correct |
140 ms |
9556 KB |
Output is correct |
32 |
Correct |
134 ms |
9440 KB |
Output is correct |
33 |
Correct |
194 ms |
9916 KB |
Output is correct |
34 |
Correct |
135 ms |
8968 KB |
Output is correct |
35 |
Correct |
140 ms |
9044 KB |
Output is correct |
36 |
Correct |
135 ms |
9444 KB |
Output is correct |
37 |
Correct |
169 ms |
9400 KB |
Output is correct |
38 |
Correct |
159 ms |
9688 KB |
Output is correct |
39 |
Correct |
218 ms |
10836 KB |
Output is correct |
40 |
Correct |
227 ms |
10732 KB |
Output is correct |
41 |
Correct |
300 ms |
10708 KB |
Output is correct |
42 |
Correct |
223 ms |
10448 KB |
Output is correct |