#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
//macros
typedef long long ll;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define pb push_back
#define fi first
#define se second
#define sz size()
//===================//
// begin program //
//===================//
const int MX = 5e5;
int n, m, a, b, e;
vi w, u, v;
vii adj[MX];
ll dist;
vi onPath, visited;
int getS(vii& binU, vii& binV) {
// binaray search for s
int lb=0, ub=binU.sz-1;
while(lb != ub) {
int mid=(lb+ub+1)/2;
RE(i,m) w[i] = 1;
for(ii p:binV) w[p.se] = 0;
RE(i,mid) w[binU[i].se] = 0;
if(ask(w) == dist) ub = mid-1;
else lb = mid;
}
return binU[lb].fi;
}
void find_pair(int N, vi U, vi V, int A, int B) {
n=N; a=A; b=B; u=U; v=V;
m = u.sz;
RE(i,m) {
adj[u[i]].pb({v[i], i});
adj[v[i]].pb({u[i], i});
}
w.assign(m, 0);
dist = ask(w);
// get edge e on path s - t
int lb=0, ub=m-1;
while(lb != ub) {
int mid=(lb+ub)/2;
RE(i,m) w[i] = 1;
RE(i,mid+1) w[i] = 0;
if(ask(w) == dist) ub = mid;
else lb = mid+1;
}
e = lb;
// bfs
visited.assign(n, 0);
vii binU, binV;
queue<pair<int, bool>> q;
q.push({u[e],1}); visited[u[e]] = 1; binU.pb({u[e], e});
q.push({v[e],0}); visited[v[e]] = 1; binV.pb({v[e], e});
while(!q.empty()) {
auto u = q.front(); q.pop();
for(ii v : adj[u.fi]) {
if(visited[v.fi]) continue;
visited[v.fi] = 1;
q.push({v.fi, u.se});
if(u.se) binU.pb(v);
else binV.pb(v);
}
}
int s = getS(binU, binV);
int t = getS(binV, binU);
answer(s, t);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
12032 KB |
Output is correct |
2 |
Correct |
12 ms |
12032 KB |
Output is correct |
3 |
Correct |
12 ms |
12152 KB |
Output is correct |
4 |
Correct |
12 ms |
12032 KB |
Output is correct |
5 |
Correct |
11 ms |
12032 KB |
Output is correct |
6 |
Correct |
12 ms |
12032 KB |
Output is correct |
7 |
Correct |
12 ms |
12032 KB |
Output is correct |
8 |
Correct |
12 ms |
12032 KB |
Output is correct |
9 |
Correct |
12 ms |
12032 KB |
Output is correct |
10 |
Correct |
11 ms |
12032 KB |
Output is correct |
11 |
Correct |
12 ms |
12032 KB |
Output is correct |
12 |
Correct |
13 ms |
12032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
12160 KB |
Output is correct |
2 |
Correct |
21 ms |
12952 KB |
Output is correct |
3 |
Correct |
178 ms |
19420 KB |
Output is correct |
4 |
Correct |
182 ms |
19604 KB |
Output is correct |
5 |
Correct |
139 ms |
19480 KB |
Output is correct |
6 |
Correct |
170 ms |
19464 KB |
Output is correct |
7 |
Correct |
181 ms |
19436 KB |
Output is correct |
8 |
Correct |
179 ms |
19460 KB |
Output is correct |
9 |
Correct |
152 ms |
19776 KB |
Output is correct |
10 |
Correct |
148 ms |
19452 KB |
Output is correct |
11 |
Correct |
194 ms |
18608 KB |
Output is correct |
12 |
Correct |
163 ms |
19088 KB |
Output is correct |
13 |
Correct |
154 ms |
19000 KB |
Output is correct |
14 |
Correct |
162 ms |
19104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
12928 KB |
Output is correct |
2 |
Correct |
39 ms |
13628 KB |
Output is correct |
3 |
Correct |
63 ms |
14392 KB |
Output is correct |
4 |
Correct |
134 ms |
18636 KB |
Output is correct |
5 |
Correct |
127 ms |
18684 KB |
Output is correct |
6 |
Correct |
132 ms |
19132 KB |
Output is correct |
7 |
Correct |
123 ms |
19068 KB |
Output is correct |
8 |
Correct |
131 ms |
18636 KB |
Output is correct |
9 |
Correct |
126 ms |
19056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
12160 KB |
Output is correct |
2 |
Correct |
26 ms |
12928 KB |
Output is correct |
3 |
Correct |
108 ms |
18072 KB |
Output is correct |
4 |
Correct |
146 ms |
19488 KB |
Output is correct |
5 |
Correct |
140 ms |
19464 KB |
Output is correct |
6 |
Correct |
136 ms |
19500 KB |
Output is correct |
7 |
Correct |
147 ms |
19500 KB |
Output is correct |
8 |
Correct |
136 ms |
19460 KB |
Output is correct |
9 |
Correct |
157 ms |
19280 KB |
Output is correct |
10 |
Correct |
151 ms |
19572 KB |
Output is correct |
11 |
Correct |
152 ms |
19100 KB |
Output is correct |
12 |
Correct |
157 ms |
19020 KB |
Output is correct |
13 |
Correct |
175 ms |
18604 KB |
Output is correct |
14 |
Correct |
157 ms |
18616 KB |
Output is correct |
15 |
Correct |
138 ms |
19456 KB |
Output is correct |
16 |
Correct |
137 ms |
19484 KB |
Output is correct |
17 |
Correct |
154 ms |
19048 KB |
Output is correct |
18 |
Correct |
175 ms |
19072 KB |
Output is correct |
19 |
Correct |
135 ms |
19520 KB |
Output is correct |
20 |
Correct |
156 ms |
18988 KB |
Output is correct |
21 |
Correct |
124 ms |
20244 KB |
Output is correct |
22 |
Correct |
118 ms |
20248 KB |
Output is correct |
23 |
Correct |
145 ms |
19784 KB |
Output is correct |
24 |
Correct |
153 ms |
19756 KB |
Output is correct |
25 |
Correct |
164 ms |
19104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
13048 KB |
Output is correct |
2 |
Correct |
30 ms |
13056 KB |
Output is correct |
3 |
Correct |
193 ms |
19760 KB |
Output is correct |
4 |
Correct |
183 ms |
20436 KB |
Output is correct |
5 |
Correct |
234 ms |
21340 KB |
Output is correct |
6 |
Correct |
237 ms |
21528 KB |
Output is correct |
7 |
Correct |
202 ms |
21896 KB |
Output is correct |
8 |
Correct |
229 ms |
21488 KB |
Output is correct |
9 |
Correct |
167 ms |
19172 KB |
Output is correct |
10 |
Correct |
169 ms |
19684 KB |
Output is correct |
11 |
Correct |
190 ms |
20144 KB |
Output is correct |
12 |
Correct |
219 ms |
21080 KB |
Output is correct |
13 |
Correct |
219 ms |
21572 KB |
Output is correct |
14 |
Correct |
278 ms |
21300 KB |
Output is correct |
15 |
Correct |
270 ms |
21636 KB |
Output is correct |
16 |
Correct |
195 ms |
20368 KB |
Output is correct |
17 |
Correct |
144 ms |
20056 KB |
Output is correct |
18 |
Correct |
181 ms |
20332 KB |
Output is correct |
19 |
Correct |
140 ms |
20436 KB |
Output is correct |
20 |
Correct |
143 ms |
20152 KB |
Output is correct |
21 |
Correct |
221 ms |
21808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
12928 KB |
Output is correct |
2 |
Correct |
26 ms |
13048 KB |
Output is correct |
3 |
Correct |
159 ms |
20008 KB |
Output is correct |
4 |
Correct |
184 ms |
20004 KB |
Output is correct |
5 |
Correct |
178 ms |
20552 KB |
Output is correct |
6 |
Correct |
267 ms |
21616 KB |
Output is correct |
7 |
Correct |
170 ms |
20028 KB |
Output is correct |
8 |
Correct |
194 ms |
20144 KB |
Output is correct |
9 |
Correct |
168 ms |
20396 KB |
Output is correct |
10 |
Correct |
286 ms |
21720 KB |
Output is correct |
11 |
Correct |
269 ms |
21444 KB |
Output is correct |
12 |
Correct |
227 ms |
21668 KB |
Output is correct |
13 |
Correct |
182 ms |
20232 KB |
Output is correct |
14 |
Correct |
224 ms |
19780 KB |
Output is correct |
15 |
Correct |
169 ms |
20116 KB |
Output is correct |
16 |
Correct |
167 ms |
19676 KB |
Output is correct |
17 |
Correct |
235 ms |
20244 KB |
Output is correct |
18 |
Correct |
192 ms |
19776 KB |
Output is correct |
19 |
Correct |
275 ms |
21008 KB |
Output is correct |
20 |
Correct |
278 ms |
21292 KB |
Output is correct |
21 |
Correct |
282 ms |
21768 KB |
Output is correct |
22 |
Correct |
237 ms |
21332 KB |
Output is correct |
23 |
Correct |
228 ms |
21448 KB |
Output is correct |
24 |
Correct |
219 ms |
21632 KB |
Output is correct |
25 |
Correct |
276 ms |
21528 KB |
Output is correct |
26 |
Correct |
224 ms |
22016 KB |
Output is correct |
27 |
Correct |
142 ms |
20188 KB |
Output is correct |
28 |
Correct |
144 ms |
20076 KB |
Output is correct |
29 |
Correct |
142 ms |
20480 KB |
Output is correct |
30 |
Correct |
166 ms |
20240 KB |
Output is correct |
31 |
Correct |
147 ms |
20240 KB |
Output is correct |
32 |
Correct |
148 ms |
20176 KB |
Output is correct |
33 |
Correct |
192 ms |
20388 KB |
Output is correct |
34 |
Correct |
143 ms |
20100 KB |
Output is correct |
35 |
Correct |
125 ms |
20060 KB |
Output is correct |
36 |
Correct |
147 ms |
20084 KB |
Output is correct |
37 |
Correct |
147 ms |
20368 KB |
Output is correct |
38 |
Correct |
155 ms |
20128 KB |
Output is correct |
39 |
Correct |
236 ms |
21756 KB |
Output is correct |
40 |
Correct |
204 ms |
21784 KB |
Output is correct |
41 |
Correct |
217 ms |
21668 KB |
Output is correct |
42 |
Correct |
225 ms |
21376 KB |
Output is correct |