#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i , j , k) for(int i = j; i < (int)k; i++)
#define all(x) x.begin(),x.end()
#define pb push_back
inline bool smin(int &a , int b) { return b < a ? a = b , true : false; }
typedef vector<int> vi;
typedef long long ll;
void find_pair(int N, vi U, vi V, int A, int B) {
int M = U.size();
vector<vi> adj(N);
rep(i , 0 , M) {
adj[U[i]].pb(i);
adj[V[i]].pb(i);
}
// faze 1 : peyda kardan fasele
int len = ask(vi(M)) / A;
// faze 2 : peyda kardane ye yal to masir
int lovelyEdge = -1;
{
int lo = -1 , hi = M - 1;
while (lo != hi - 1) {
int mid = lo + hi >> 1;
vi local(mid + 1 , 1);
local.resize(M);
if (ask(local) != 1ll * A * len)
hi = mid;
else
lo = mid;
}
lovelyEdge = hi;
}
// faze 3 : peyda kardane rasaye chap va rasaye rast va sakhtane deralht chap o rast :
vector<bool> active(N , true);
vi d1(N) , d2(N), d3(N);
vi edge1, edge2;
auto bfs = [&](int v , vi &d, vi& edge) {
edge.clear();
edge.pb(lovelyEdge);
fill(all(d) , 1e9);
vi q(N);
int L = 0 , R = 0;
assert(active[v]);
d[v] = 0;
q[R++] = v;
while (L < R) {
v = q[L++];
for (auto e : adj[v]) {
int u = V[e] ^ U[e] ^ v;
if (!active[u]) continue;
if (smin(d[u] , d[v] + 1))
q[R++] = u;
if (d[u] == d[v] + 1) {
if (V[e] == u)
swap(U[e] , V[e]);
edge.pb(e);
}
}
}
return;
};
int V1 = V[lovelyEdge];
int V2 = U[lovelyEdge];
bfs(V1 , d1 , edge1);
bfs(V2 , d2 , edge2);
fill(all(active) , false);
rep(i , 0 , N) if (d1[i] < d2[i]) active[i] = true;
bfs(V1 , d3 , edge1);
fill(all(active) , false);
rep(i , 0 , N) if (d2[i] < d1[i]) active[i] = true;
bfs(V2 , d3 , edge2);
// faze 4 : peyd akardan s O t:
auto finder = [&](int root, vi&d , vi & edge) {
ll len2 = -1;
{
vi local(M , 1);
for (auto e : edge) local[e] = 0;
len2 = ask(local);
}
int lo = -1, hi = edge.size() - 1;
while (lo != hi - 1) {
int mid = lo + hi >> 1;
vi local(M , 1);
rep(i , 0 , mid + 1)
local[edge[i]] = 0;
if (ask(local) == len2) hi = mid;
else lo = mid;
}
if (hi == 0) return root;
return U[edge[hi]];
};
int S = finder(V1 , d1 , edge1);
int T = finder(V2 , d2 ,edge2);
if (true)
assert(d1[S] + 1 + d2[T] <= len);
answer(S , T);
return;
}
Compilation message
highway.cpp: In function 'void find_pair(int, vi, vi, int, int)':
highway.cpp:34:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = lo + hi >> 1;
~~~^~~~
highway.cpp: In lambda function:
highway.cpp:112:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = lo + hi >> 1;
~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
324 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
248 KB |
Output is correct |
6 |
Correct |
2 ms |
324 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
380 KB |
Output is correct |
10 |
Correct |
2 ms |
248 KB |
Output is correct |
11 |
Correct |
2 ms |
328 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
380 KB |
Output is correct |
2 |
Correct |
23 ms |
1288 KB |
Output is correct |
3 |
Correct |
246 ms |
9320 KB |
Output is correct |
4 |
Correct |
242 ms |
9388 KB |
Output is correct |
5 |
Correct |
202 ms |
9396 KB |
Output is correct |
6 |
Correct |
190 ms |
9392 KB |
Output is correct |
7 |
Correct |
249 ms |
9324 KB |
Output is correct |
8 |
Correct |
220 ms |
9388 KB |
Output is correct |
9 |
Correct |
223 ms |
9508 KB |
Output is correct |
10 |
Correct |
212 ms |
9364 KB |
Output is correct |
11 |
Correct |
260 ms |
9280 KB |
Output is correct |
12 |
Correct |
235 ms |
9296 KB |
Output is correct |
13 |
Correct |
265 ms |
9264 KB |
Output is correct |
14 |
Correct |
251 ms |
9292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
1344 KB |
Output is correct |
2 |
Correct |
67 ms |
2376 KB |
Output is correct |
3 |
Correct |
61 ms |
3340 KB |
Output is correct |
4 |
Correct |
165 ms |
9276 KB |
Output is correct |
5 |
Correct |
169 ms |
9288 KB |
Output is correct |
6 |
Correct |
174 ms |
9288 KB |
Output is correct |
7 |
Correct |
151 ms |
9336 KB |
Output is correct |
8 |
Correct |
159 ms |
9268 KB |
Output is correct |
9 |
Correct |
140 ms |
9332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
296 KB |
Output is correct |
2 |
Correct |
22 ms |
1276 KB |
Output is correct |
3 |
Correct |
164 ms |
7504 KB |
Output is correct |
4 |
Correct |
250 ms |
9392 KB |
Output is correct |
5 |
Correct |
229 ms |
9380 KB |
Output is correct |
6 |
Correct |
210 ms |
9380 KB |
Output is correct |
7 |
Correct |
199 ms |
9376 KB |
Output is correct |
8 |
Correct |
215 ms |
9376 KB |
Output is correct |
9 |
Correct |
190 ms |
9324 KB |
Output is correct |
10 |
Correct |
217 ms |
9388 KB |
Output is correct |
11 |
Correct |
226 ms |
9284 KB |
Output is correct |
12 |
Correct |
272 ms |
9288 KB |
Output is correct |
13 |
Correct |
255 ms |
9304 KB |
Output is correct |
14 |
Correct |
232 ms |
9284 KB |
Output is correct |
15 |
Correct |
215 ms |
9316 KB |
Output is correct |
16 |
Correct |
227 ms |
9324 KB |
Output is correct |
17 |
Correct |
239 ms |
9240 KB |
Output is correct |
18 |
Correct |
244 ms |
9288 KB |
Output is correct |
19 |
Correct |
206 ms |
9328 KB |
Output is correct |
20 |
Correct |
298 ms |
9300 KB |
Output is correct |
21 |
Correct |
193 ms |
9648 KB |
Output is correct |
22 |
Correct |
164 ms |
9672 KB |
Output is correct |
23 |
Correct |
177 ms |
9604 KB |
Output is correct |
24 |
Correct |
201 ms |
9620 KB |
Output is correct |
25 |
Correct |
222 ms |
9348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
17 ms |
2536 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
28 ms |
2604 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |