#include "highway.h"
#include <vector>
#include <iostream>
#include <queue>
using namespace std;
const int maxN = 90'000;
const int light = 0;
const int heavy = 1;
const int INF = 1e9;
int N;
vector<int> U;
vector<int> V;
long long A;
long long B;
int M;
int getV(int u, int e)
{
return U[e] + V[e] - u;
}
vector<int> edge[maxN];
int middleEdge;
long long DA;
int X, Y;
const int Xtree = 0;
const int Ytree = 1;
const int notree = -1;
const int noedge = -1;
void find_pair(int n, vector<int> u, vector<int> v, int a, int b)
{
N = n;
U = u;
V = v;
A = a;
B = b;
M = U.size();
for(int j = 0; j < M; j++)
{
edge[ U[j] ].push_back(j);
edge[ V[j] ].push_back(j);
}
DA = ask(vector<int>(M, light));
int lo = 0;
int hi = M-1;
while(lo != hi)
{
int mid = (lo+hi)/2;
vector<int> w(M);
for(int j = 0; j < M; j++)
{
if(j <= mid)
w[j] = heavy;
else
w[j] = light;
}
if(ask(w) > DA) hi = mid;
else lo = mid+1;
}
int middleEdge = lo;
cerr << middleEdge << '\n';
X = U[middleEdge]; //0
Y = V[middleEdge]; //1
vector<int> dist(N, INF);
vector<int> tree(N, notree);
vector<int> parentEdge(N, noedge);
dist[X] = 0;
tree[X] = Xtree;
parentEdge[X] = noedge;
dist[Y] = 0;
tree[Y] = Ytree;
parentEdge[Y] = noedge;
queue<int> tbv;
tbv.push(X);
tbv.push(Y);
vector<int> treelist[2];
while(!tbv.empty())
{
int P = tbv.front();
treelist[tree[P]].push_back(P);
tbv.pop();
for(int e: edge[P])
{
int Q = getV(P, e);
if(dist[P] + 1 >= dist[Q]) continue;
dist[Q] = dist[P] + 1;
tree[Q] = tree[P];
parentEdge[Q] = e;
tbv.push(Q);
}
}
// for(int i = 0; i < N; i++) cerr << dist[i] << ' ' << tree[i] << ' ' << parentEdge[i] << '\n';
vector<int> ans;
for(int Z = 0; Z < 2; Z++)
{
lo = 0;
hi = int(treelist[Z].size()) - 1;
// cerr << "Z = " << Z << '\n';
// if(Z == 1)
// for(int t: treelist[Z]) cerr << t << ' ';
// cerr << '\n';
// cerr << lo << ' ' << hi << '\n';
while(lo != hi)
{
int mid = (lo+hi)/2;
vector<int> w(M, heavy);
w[middleEdge] = light;
for(int i = 0; i < N; i++)
if(parentEdge[i] != noedge)
w[parentEdge[i]] = light;
// cerr << "mid = " << mid << '\n';
// for(int i = 0; i <= mid; i++)
// {
// if(parentEdge[ treelist[Z][i] ] != noedge)
// w[ parentEdge[ treelist[Z][i] ] ] = light;
// }
for(int i = mid+1; i <= hi; i++)
{
if(parentEdge[ treelist[Z][i] ] != noedge)
w[ parentEdge[ treelist[Z][i] ] ] = heavy;
}
// cerr << "query = ";
// for(int h: w) cerr << h << ' ';
// cerr << '\n';
if(ask(w) > DA)
lo = mid+1;
else
hi = mid;
// cerr << lo << ' ' << hi << '\n';
}
ans.push_back(treelist[Z][lo]);
}
answer(ans[0], ans[1]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2376 KB |
Output is correct |
2 |
Correct |
2 ms |
2376 KB |
Output is correct |
3 |
Correct |
2 ms |
2376 KB |
Output is correct |
4 |
Correct |
3 ms |
2376 KB |
Output is correct |
5 |
Correct |
2 ms |
2376 KB |
Output is correct |
6 |
Correct |
2 ms |
2376 KB |
Output is correct |
7 |
Correct |
2 ms |
2376 KB |
Output is correct |
8 |
Correct |
2 ms |
2376 KB |
Output is correct |
9 |
Correct |
2 ms |
2376 KB |
Output is correct |
10 |
Correct |
2 ms |
2376 KB |
Output is correct |
11 |
Correct |
2 ms |
2376 KB |
Output is correct |
12 |
Correct |
2 ms |
2408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2376 KB |
Output is correct |
2 |
Correct |
20 ms |
3144 KB |
Output is correct |
3 |
Correct |
170 ms |
9388 KB |
Output is correct |
4 |
Correct |
176 ms |
9432 KB |
Output is correct |
5 |
Correct |
188 ms |
9472 KB |
Output is correct |
6 |
Correct |
136 ms |
9312 KB |
Output is correct |
7 |
Correct |
188 ms |
9456 KB |
Output is correct |
8 |
Correct |
181 ms |
9364 KB |
Output is correct |
9 |
Correct |
159 ms |
9356 KB |
Output is correct |
10 |
Correct |
188 ms |
9360 KB |
Output is correct |
11 |
Correct |
135 ms |
9404 KB |
Output is correct |
12 |
Correct |
197 ms |
9316 KB |
Output is correct |
13 |
Correct |
181 ms |
9280 KB |
Output is correct |
14 |
Correct |
157 ms |
9320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
3144 KB |
Output is correct |
2 |
Correct |
35 ms |
3952 KB |
Output is correct |
3 |
Correct |
51 ms |
4744 KB |
Output is correct |
4 |
Correct |
124 ms |
9456 KB |
Output is correct |
5 |
Correct |
116 ms |
9344 KB |
Output is correct |
6 |
Correct |
152 ms |
9328 KB |
Output is correct |
7 |
Correct |
128 ms |
9268 KB |
Output is correct |
8 |
Correct |
122 ms |
9452 KB |
Output is correct |
9 |
Correct |
111 ms |
9268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2376 KB |
Output is correct |
2 |
Correct |
15 ms |
3136 KB |
Output is correct |
3 |
Correct |
137 ms |
7880 KB |
Output is correct |
4 |
Correct |
126 ms |
9400 KB |
Output is correct |
5 |
Correct |
177 ms |
9360 KB |
Output is correct |
6 |
Correct |
173 ms |
9428 KB |
Output is correct |
7 |
Correct |
156 ms |
9368 KB |
Output is correct |
8 |
Correct |
156 ms |
9352 KB |
Output is correct |
9 |
Correct |
138 ms |
9444 KB |
Output is correct |
10 |
Correct |
180 ms |
9468 KB |
Output is correct |
11 |
Correct |
185 ms |
9260 KB |
Output is correct |
12 |
Correct |
158 ms |
9288 KB |
Output is correct |
13 |
Correct |
183 ms |
9340 KB |
Output is correct |
14 |
Correct |
146 ms |
9428 KB |
Output is correct |
15 |
Correct |
179 ms |
9364 KB |
Output is correct |
16 |
Correct |
144 ms |
9440 KB |
Output is correct |
17 |
Correct |
187 ms |
9280 KB |
Output is correct |
18 |
Correct |
133 ms |
9280 KB |
Output is correct |
19 |
Correct |
146 ms |
9360 KB |
Output is correct |
20 |
Correct |
140 ms |
9336 KB |
Output is correct |
21 |
Correct |
135 ms |
9896 KB |
Output is correct |
22 |
Correct |
161 ms |
9944 KB |
Output is correct |
23 |
Correct |
121 ms |
10020 KB |
Output is correct |
24 |
Correct |
180 ms |
9992 KB |
Output is correct |
25 |
Correct |
221 ms |
9340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
3208 KB |
Output is correct |
2 |
Correct |
20 ms |
3120 KB |
Output is correct |
3 |
Correct |
158 ms |
9744 KB |
Output is correct |
4 |
Correct |
223 ms |
10072 KB |
Output is correct |
5 |
Correct |
288 ms |
10728 KB |
Output is correct |
6 |
Correct |
279 ms |
10908 KB |
Output is correct |
7 |
Correct |
258 ms |
10968 KB |
Output is correct |
8 |
Correct |
273 ms |
11012 KB |
Output is correct |
9 |
Correct |
170 ms |
8388 KB |
Output is correct |
10 |
Correct |
212 ms |
8628 KB |
Output is correct |
11 |
Correct |
178 ms |
9024 KB |
Output is correct |
12 |
Correct |
224 ms |
10308 KB |
Output is correct |
13 |
Correct |
220 ms |
10584 KB |
Output is correct |
14 |
Correct |
215 ms |
10876 KB |
Output is correct |
15 |
Correct |
268 ms |
10524 KB |
Output is correct |
16 |
Correct |
224 ms |
9216 KB |
Output is correct |
17 |
Correct |
162 ms |
10252 KB |
Output is correct |
18 |
Correct |
172 ms |
10216 KB |
Output is correct |
19 |
Correct |
163 ms |
10192 KB |
Output is correct |
20 |
Correct |
128 ms |
10156 KB |
Output is correct |
21 |
Correct |
267 ms |
10460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
3144 KB |
Output is correct |
2 |
Correct |
19 ms |
3228 KB |
Output is correct |
3 |
Correct |
210 ms |
9976 KB |
Output is correct |
4 |
Correct |
230 ms |
10152 KB |
Output is correct |
5 |
Correct |
233 ms |
10052 KB |
Output is correct |
6 |
Correct |
222 ms |
11004 KB |
Output is correct |
7 |
Correct |
200 ms |
9676 KB |
Output is correct |
8 |
Correct |
215 ms |
9836 KB |
Output is correct |
9 |
Correct |
234 ms |
10232 KB |
Output is correct |
10 |
Correct |
207 ms |
11024 KB |
Output is correct |
11 |
Correct |
276 ms |
10924 KB |
Output is correct |
12 |
Correct |
275 ms |
10892 KB |
Output is correct |
13 |
Correct |
173 ms |
8980 KB |
Output is correct |
14 |
Correct |
216 ms |
8628 KB |
Output is correct |
15 |
Correct |
182 ms |
8996 KB |
Output is correct |
16 |
Correct |
225 ms |
8680 KB |
Output is correct |
17 |
Correct |
171 ms |
8984 KB |
Output is correct |
18 |
Correct |
214 ms |
8644 KB |
Output is correct |
19 |
Correct |
212 ms |
10292 KB |
Output is correct |
20 |
Correct |
221 ms |
10232 KB |
Output is correct |
21 |
Correct |
224 ms |
10724 KB |
Output is correct |
22 |
Correct |
270 ms |
10860 KB |
Output is correct |
23 |
Correct |
233 ms |
10724 KB |
Output is correct |
24 |
Correct |
245 ms |
10844 KB |
Output is correct |
25 |
Correct |
226 ms |
10888 KB |
Output is correct |
26 |
Correct |
213 ms |
11012 KB |
Output is correct |
27 |
Correct |
144 ms |
10128 KB |
Output is correct |
28 |
Correct |
139 ms |
10060 KB |
Output is correct |
29 |
Correct |
148 ms |
10188 KB |
Output is correct |
30 |
Correct |
149 ms |
10096 KB |
Output is correct |
31 |
Correct |
134 ms |
10100 KB |
Output is correct |
32 |
Correct |
178 ms |
10132 KB |
Output is correct |
33 |
Correct |
176 ms |
10244 KB |
Output is correct |
34 |
Correct |
163 ms |
10092 KB |
Output is correct |
35 |
Correct |
171 ms |
10076 KB |
Output is correct |
36 |
Correct |
128 ms |
10024 KB |
Output is correct |
37 |
Correct |
188 ms |
10168 KB |
Output is correct |
38 |
Correct |
145 ms |
10088 KB |
Output is correct |
39 |
Correct |
279 ms |
10628 KB |
Output is correct |
40 |
Correct |
287 ms |
10652 KB |
Output is correct |
41 |
Correct |
192 ms |
10452 KB |
Output is correct |
42 |
Correct |
273 ms |
10684 KB |
Output is correct |