#include <bits/stdc++.h>
#include "highway.h"
using namespace std;
const int maxn = 2e5+10;
typedef pair<int, int> pii;
typedef long long ll;
int M;
ll D;
vector<pii> grafo[maxn], tree[2][maxn];
int pai[2][maxn], edge[2][maxn];
int dist[2][maxn];
bool is[maxn];
void bfs(int s, int k)
{
queue<int> fila;
dist[k][s] = 0, fila.push(s);
while (!fila.empty())
{
int u = fila.front(); fila.pop();
for (auto pp: grafo[u])
{
int v = pp.first, e = pp.second;
if (dist[k][v] == -1)
{
dist[k][v] = dist[k][u]+1, pai[k][v] = u, edge[k][v] = e;
fila.push(v);
}
}
}
}
vector<int> lista[2];
void dfs(int u, int p, int k)
{
for (auto pp: tree[k][u])
if (pp.first != p)
dfs(pp.first, u, k);
lista[k].push_back(u);
}
int get(int k)
{
int ini = 0, fim = (int)(lista[k].size())-2, ans = lista[k].back();
while (ini <= fim)
{
int mid = (ini+fim)>>1;
vector<int> w(M, 1);
for (int i = 0; i < M; i++)
if (is[i])
w[i] = 0;
for (int i = 0; i <= mid; i++)
w[edge[k][lista[k][i]]] = 1;
ll d = ask(w);
if (d > D) ans = lista[k][mid], fim = mid-1;
else ini = mid+1;
}
return ans;
}
void find_pair(int N, vector<int> U, vector<int> V, int A, int B)
{
M = U.size();
vector<int> w(M);
D = ask(w);
int ini = 0, fim = M-1, ind = 0;
while (ini <= fim)
{
int mid = (ini+fim)>>1;
for (int i = 0; i <= mid; i++)
w[i] = 1;
ll d = ask(w);
if (d > D) ind = mid, fim = mid-1;
else ini = mid+1;
for (int i = 0; i <= mid; i++)
w[i] = 0;
}
for (int i = ind; i < M; i++)
{
grafo[U[i]].push_back({V[i], i});
grafo[V[i]].push_back({U[i], i});
}
memset(dist, -1, sizeof dist);
bfs(U[ind], 0); bfs(V[ind], 1);
is[ind] = 1;
for (int i = 0; i < N; i++)
{
if (dist[0][i] == dist[1][i] || i == U[ind] || i == V[ind]) continue;
if (dist[0][i] < dist[1][i])
{
is[edge[0][i]] = 1;
tree[1][i].push_back({pai[0][i], edge[0][i]});
tree[0][pai[0][i]].push_back({i, edge[0][i]});
}
else
{
is[edge[1][i]] = 1;
tree[1][i].push_back({pai[1][i], edge[1][i]});
tree[1][pai[1][i]].push_back({i, edge[1][i]});
}
}
dfs(U[ind], -1, 0); dfs(V[ind], -1, 1);
answer(get(0), get(1));
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
15944 KB |
Output is correct |
2 |
Correct |
9 ms |
15944 KB |
Output is correct |
3 |
Correct |
9 ms |
15944 KB |
Output is correct |
4 |
Correct |
9 ms |
15944 KB |
Output is correct |
5 |
Correct |
9 ms |
15928 KB |
Output is correct |
6 |
Correct |
9 ms |
15944 KB |
Output is correct |
7 |
Correct |
9 ms |
15944 KB |
Output is correct |
8 |
Correct |
9 ms |
15912 KB |
Output is correct |
9 |
Correct |
9 ms |
15944 KB |
Output is correct |
10 |
Correct |
9 ms |
15944 KB |
Output is correct |
11 |
Correct |
10 ms |
15940 KB |
Output is correct |
12 |
Correct |
9 ms |
15928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
16076 KB |
Output is correct |
2 |
Correct |
28 ms |
17400 KB |
Output is correct |
3 |
Correct |
206 ms |
26836 KB |
Output is correct |
4 |
Correct |
226 ms |
25816 KB |
Output is correct |
5 |
Correct |
177 ms |
26816 KB |
Output is correct |
6 |
Correct |
188 ms |
24852 KB |
Output is correct |
7 |
Correct |
185 ms |
24460 KB |
Output is correct |
8 |
Correct |
208 ms |
26768 KB |
Output is correct |
9 |
Correct |
195 ms |
25100 KB |
Output is correct |
10 |
Correct |
179 ms |
25624 KB |
Output is correct |
11 |
Correct |
129 ms |
23408 KB |
Output is correct |
12 |
Correct |
181 ms |
29040 KB |
Output is correct |
13 |
Correct |
220 ms |
26988 KB |
Output is correct |
14 |
Correct |
193 ms |
29700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
17408 KB |
Output is correct |
2 |
Correct |
35 ms |
18880 KB |
Output is correct |
3 |
Correct |
55 ms |
17160 KB |
Output is correct |
4 |
Correct |
117 ms |
26248 KB |
Output is correct |
5 |
Correct |
159 ms |
26500 KB |
Output is correct |
6 |
Correct |
146 ms |
28700 KB |
Output is correct |
7 |
Correct |
153 ms |
18824 KB |
Output is correct |
8 |
Correct |
129 ms |
27348 KB |
Output is correct |
9 |
Correct |
132 ms |
21860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
16072 KB |
Output is correct |
2 |
Correct |
31 ms |
17024 KB |
Output is correct |
3 |
Correct |
167 ms |
24316 KB |
Output is correct |
4 |
Correct |
157 ms |
25684 KB |
Output is correct |
5 |
Correct |
155 ms |
22508 KB |
Output is correct |
6 |
Correct |
143 ms |
22816 KB |
Output is correct |
7 |
Correct |
181 ms |
24928 KB |
Output is correct |
8 |
Correct |
153 ms |
23064 KB |
Output is correct |
9 |
Correct |
205 ms |
27016 KB |
Output is correct |
10 |
Correct |
206 ms |
25776 KB |
Output is correct |
11 |
Correct |
179 ms |
29148 KB |
Output is correct |
12 |
Correct |
231 ms |
27452 KB |
Output is correct |
13 |
Correct |
236 ms |
27904 KB |
Output is correct |
14 |
Correct |
143 ms |
23824 KB |
Output is correct |
15 |
Correct |
160 ms |
22636 KB |
Output is correct |
16 |
Correct |
102 ms |
20552 KB |
Output is correct |
17 |
Correct |
191 ms |
28588 KB |
Output is correct |
18 |
Correct |
217 ms |
29992 KB |
Output is correct |
19 |
Correct |
109 ms |
21796 KB |
Output is correct |
20 |
Correct |
167 ms |
22632 KB |
Output is correct |
21 |
Correct |
171 ms |
24380 KB |
Output is correct |
22 |
Correct |
117 ms |
21584 KB |
Output is correct |
23 |
Correct |
188 ms |
27348 KB |
Output is correct |
24 |
Correct |
180 ms |
27676 KB |
Output is correct |
25 |
Correct |
230 ms |
33168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
17088 KB |
Output is correct |
2 |
Correct |
26 ms |
17296 KB |
Output is correct |
3 |
Correct |
209 ms |
26996 KB |
Output is correct |
4 |
Correct |
226 ms |
26708 KB |
Output is correct |
5 |
Correct |
292 ms |
27076 KB |
Output is correct |
6 |
Correct |
240 ms |
27808 KB |
Output is correct |
7 |
Correct |
301 ms |
27256 KB |
Output is correct |
8 |
Correct |
216 ms |
28292 KB |
Output is correct |
9 |
Correct |
184 ms |
19800 KB |
Output is correct |
10 |
Correct |
149 ms |
21824 KB |
Output is correct |
11 |
Correct |
179 ms |
23208 KB |
Output is correct |
12 |
Correct |
237 ms |
26552 KB |
Output is correct |
13 |
Correct |
244 ms |
27080 KB |
Output is correct |
14 |
Correct |
356 ms |
28184 KB |
Output is correct |
15 |
Correct |
334 ms |
28884 KB |
Output is correct |
16 |
Correct |
199 ms |
24144 KB |
Output is correct |
17 |
Correct |
159 ms |
25932 KB |
Output is correct |
18 |
Correct |
139 ms |
22784 KB |
Output is correct |
19 |
Correct |
148 ms |
26428 KB |
Output is correct |
20 |
Correct |
168 ms |
24404 KB |
Output is correct |
21 |
Correct |
336 ms |
28892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
17184 KB |
Output is correct |
2 |
Correct |
33 ms |
17348 KB |
Output is correct |
3 |
Correct |
264 ms |
27028 KB |
Output is correct |
4 |
Correct |
254 ms |
26684 KB |
Output is correct |
5 |
Correct |
235 ms |
26780 KB |
Output is correct |
6 |
Correct |
286 ms |
28272 KB |
Output is correct |
7 |
Correct |
255 ms |
27120 KB |
Output is correct |
8 |
Correct |
265 ms |
27088 KB |
Output is correct |
9 |
Correct |
216 ms |
26644 KB |
Output is correct |
10 |
Correct |
264 ms |
27400 KB |
Output is correct |
11 |
Correct |
324 ms |
27904 KB |
Output is correct |
12 |
Correct |
304 ms |
27416 KB |
Output is correct |
13 |
Correct |
155 ms |
19752 KB |
Output is correct |
14 |
Correct |
203 ms |
19488 KB |
Output is correct |
15 |
Correct |
268 ms |
24752 KB |
Output is correct |
16 |
Correct |
159 ms |
21792 KB |
Output is correct |
17 |
Correct |
238 ms |
23140 KB |
Output is correct |
18 |
Correct |
246 ms |
22100 KB |
Output is correct |
19 |
Correct |
257 ms |
26284 KB |
Output is correct |
20 |
Correct |
314 ms |
27852 KB |
Output is correct |
21 |
Correct |
318 ms |
27812 KB |
Output is correct |
22 |
Correct |
295 ms |
27668 KB |
Output is correct |
23 |
Correct |
340 ms |
28040 KB |
Output is correct |
24 |
Correct |
311 ms |
27908 KB |
Output is correct |
25 |
Correct |
242 ms |
28180 KB |
Output is correct |
26 |
Correct |
265 ms |
28464 KB |
Output is correct |
27 |
Correct |
142 ms |
24224 KB |
Output is correct |
28 |
Correct |
192 ms |
25888 KB |
Output is correct |
29 |
Correct |
155 ms |
27752 KB |
Output is correct |
30 |
Correct |
189 ms |
26984 KB |
Output is correct |
31 |
Correct |
165 ms |
26556 KB |
Output is correct |
32 |
Correct |
184 ms |
26456 KB |
Output is correct |
33 |
Correct |
161 ms |
27744 KB |
Output is correct |
34 |
Correct |
183 ms |
25644 KB |
Output is correct |
35 |
Correct |
139 ms |
25816 KB |
Output is correct |
36 |
Correct |
172 ms |
26680 KB |
Output is correct |
37 |
Correct |
149 ms |
26452 KB |
Output is correct |
38 |
Correct |
196 ms |
26608 KB |
Output is correct |
39 |
Correct |
277 ms |
29304 KB |
Output is correct |
40 |
Correct |
289 ms |
30560 KB |
Output is correct |
41 |
Correct |
305 ms |
28684 KB |
Output is correct |
42 |
Correct |
279 ms |
29456 KB |
Output is correct |