#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
#define debug(s) cout << #s << " = " << s << endl
typedef long long ll;
typedef pair<int, int> ii;
const int maxn = 500005;
namespace {
vector<int> L, R, g[maxn], t[maxn], vis, lvl, pe, wot, where;
ll pathLen, A, B;
int S, T, tym = 0, n, m;
}
void bfs(int root) {
queue<int> Q;
Q.emplace(root);
lvl[root] = 0;
pe[root] = -1, vis[root] = 1;
while(Q.size()) {
int u = Q.front();
Q.pop();
for(int i : g[u]) {
int v = L[i] ^ R[i] ^ u;
if(!vis[v]) {
vis[v] = 1;
Q.emplace(v);
lvl[v] = lvl[u] + 1;
pe[v] = i;
t[u].emplace_back(i);
t[v].emplace_back(i);
}
}
}
}
void dfs(int u) {
vis[u] = 1;
wot[tym] = u;
where[u] = tym++;
for(int i : t[u]) {
int v = L[i] ^ R[i] ^ u;
if(!vis[v]) {
dfs(v);
}
}
}
void find_pair(int _N, std::vector<int> _U, std::vector<int> _V, int _A, int _B) {
n = _N, L = _U, R = _V, A = _A, B = _B, m = _U.size();
vis.assign(n, 0), lvl.assign(n, 0), pe.assign(n, 0), wot.assign(n, 0), where.assign(n, 0);
for(int i = 0; i < m; i++) {
g[L[i]].emplace_back(i);
g[R[i]].emplace_back(i);
// cout << i << " ----> " << L[i] << ' ' << R[i] << endl;
}
{
vector<int> w(m);
pathLen = ask(w) / A;
// debug(pathLen);
}
int root;
{
int lo = 0, hi = m - 1, mid, ret = -1;
while(lo <= hi) {
mid = lo + hi >> 1;
vector<int> w(m);
for(int i = 0; i <= mid; i++) {
w[i] = 1;
}
if(ask(w) != A * pathLen) {
ret = mid;
hi = mid - 1;
} else {
lo = mid + 1;
}
}
root = ret == -1 ? -1 : L[ret];
}
// debug(root);
bfs(root);
fill(vis.begin(), vis.end(), 0);
dfs(root);
// for(int b : wot) cout << b << ' '; cout << endl;
// for(int b : pe) cout << b << ' '; cout << endl;
S = T = -1;
{
int lo = 0, hi = n - 1, mid;
while(lo <= hi) {
mid = lo + hi >> 1;
vector<int> w(m, 1);
for(int i = 0; i <= mid; i++) {
w[pe[wot[i]]] = 0;
}
if(ask(w) == A * pathLen) {
S = wot[mid];
hi = mid - 1;
} else {
lo = mid + 1;
}
}
}
{
int lo = 0, hi = n - 1, mid;
while(lo <= hi) {
mid = lo + hi >> 1;
vector<int> w(m, 1);
for(int i = 0; i <= mid; i++) {
w[pe[wot[i]]] = 0;
}
int u = S;
while(pe[u] != -1) {
w[pe[u]] = 1;
u = u ^ L[pe[u]] ^ R[pe[u]];
}
// for(int i = 0; i < m; i++) cout << i << ' '; cout << endl;
// for(int b : w) cout << b << ' '; cout << endl;
// debug(ask(w));
if(ask(w) == A * (pathLen - lvl[S]) + B * lvl[S]) {
T = wot[mid];
hi = mid - 1;
} else {
lo = mid + 1;
}
}
}
// debug(S), debug(T);
answer(S, T);
}
Compilation message
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:76:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
mid = lo + hi >> 1;
~~~^~~~
highway.cpp:104:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
mid = lo + hi >> 1;
~~~^~~~
highway.cpp:121:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
mid = lo + hi >> 1;
~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
23800 KB |
Output is correct |
2 |
Correct |
24 ms |
23800 KB |
Output is correct |
3 |
Correct |
24 ms |
23800 KB |
Output is correct |
4 |
Correct |
23 ms |
23808 KB |
Output is correct |
5 |
Correct |
24 ms |
23800 KB |
Output is correct |
6 |
Correct |
25 ms |
23784 KB |
Output is correct |
7 |
Correct |
23 ms |
23804 KB |
Output is correct |
8 |
Correct |
23 ms |
23800 KB |
Output is correct |
9 |
Correct |
24 ms |
23800 KB |
Output is correct |
10 |
Correct |
24 ms |
23808 KB |
Output is correct |
11 |
Correct |
24 ms |
23816 KB |
Output is correct |
12 |
Correct |
24 ms |
23808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
23928 KB |
Output is correct |
2 |
Correct |
46 ms |
24924 KB |
Output is correct |
3 |
Correct |
315 ms |
33988 KB |
Output is correct |
4 |
Correct |
326 ms |
33988 KB |
Output is correct |
5 |
Correct |
323 ms |
34036 KB |
Output is correct |
6 |
Correct |
301 ms |
34000 KB |
Output is correct |
7 |
Correct |
338 ms |
34004 KB |
Output is correct |
8 |
Correct |
298 ms |
33912 KB |
Output is correct |
9 |
Correct |
304 ms |
34004 KB |
Output is correct |
10 |
Correct |
343 ms |
33896 KB |
Output is correct |
11 |
Correct |
317 ms |
34252 KB |
Output is correct |
12 |
Correct |
315 ms |
34600 KB |
Output is correct |
13 |
Correct |
319 ms |
34408 KB |
Output is correct |
14 |
Correct |
293 ms |
34448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
25208 KB |
Output is correct |
2 |
Correct |
62 ms |
26580 KB |
Output is correct |
3 |
Correct |
89 ms |
27924 KB |
Output is correct |
4 |
Correct |
192 ms |
35512 KB |
Output is correct |
5 |
Correct |
220 ms |
35464 KB |
Output is correct |
6 |
Correct |
238 ms |
35956 KB |
Output is correct |
7 |
Correct |
215 ms |
36368 KB |
Output is correct |
8 |
Correct |
204 ms |
35692 KB |
Output is correct |
9 |
Correct |
194 ms |
35792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
23884 KB |
Output is correct |
2 |
Correct |
47 ms |
24952 KB |
Output is correct |
3 |
Correct |
245 ms |
31696 KB |
Output is correct |
4 |
Correct |
336 ms |
33888 KB |
Output is correct |
5 |
Correct |
251 ms |
33912 KB |
Output is correct |
6 |
Correct |
292 ms |
33996 KB |
Output is correct |
7 |
Correct |
260 ms |
33912 KB |
Output is correct |
8 |
Correct |
280 ms |
33896 KB |
Output is correct |
9 |
Correct |
297 ms |
33896 KB |
Output is correct |
10 |
Correct |
283 ms |
33896 KB |
Output is correct |
11 |
Correct |
328 ms |
34280 KB |
Output is correct |
12 |
Correct |
348 ms |
34620 KB |
Output is correct |
13 |
Correct |
336 ms |
34476 KB |
Output is correct |
14 |
Correct |
344 ms |
34432 KB |
Output is correct |
15 |
Correct |
310 ms |
34000 KB |
Output is correct |
16 |
Correct |
274 ms |
33904 KB |
Output is correct |
17 |
Correct |
331 ms |
34388 KB |
Output is correct |
18 |
Correct |
306 ms |
34604 KB |
Output is correct |
19 |
Correct |
268 ms |
34004 KB |
Output is correct |
20 |
Correct |
333 ms |
34804 KB |
Output is correct |
21 |
Correct |
255 ms |
34764 KB |
Output is correct |
22 |
Correct |
265 ms |
34776 KB |
Output is correct |
23 |
Correct |
250 ms |
34704 KB |
Output is correct |
24 |
Correct |
316 ms |
34756 KB |
Output is correct |
25 |
Correct |
404 ms |
36212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
24956 KB |
Output is correct |
2 |
Correct |
54 ms |
24984 KB |
Output is correct |
3 |
Correct |
361 ms |
34216 KB |
Output is correct |
4 |
Incorrect |
370 ms |
34548 KB |
Output is incorrect: {s, t} is wrong. |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
53 ms |
24876 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |