//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include "highway.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%I64d", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%I64d\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 130050;
const double eps = 1e-9;
vii adj[MAXN], all;
int n, m, vis[MAXN], dp[MAXN], mrk[MAXN];
ll dist;
int solve(int root) {
mem(vis, 0);
mem(mrk, 0);
mem(dp, 0);
deque<int> pq;
pq.pb(root);
vis[root] = 1;
vi edg;
while (!pq.empty()) {
int u = pq.front(); pq.pop_front();
for (pii nx: adj[u]) {
if (vis[nx.fi]) continue;
vis[nx.fi] = 1;
dp[nx.fi] = dp[u] + 1;
pq.pb(nx.fi);
edg.pb(nx.se);
mrk[nx.se] = 1;
}
}
vi tmp(m);
reverse(edg.begin(), edg.end());
for (int i = 0; i < m; i++)
if (!mrk[i])
tmp[i] = 1;
if (dist == -1)
dist = ask(tmp);
int lo = 0, hi = n-1, ans = 0;
while (lo <= hi) {
int mi = (lo+hi) / 2;
for (int i = 0; i <= mi; i++)
tmp[edg[i]] = 1;
ll w = ask(tmp);
if (w == dist)
lo = mi + 1;
else
hi = mi - 1;
for (int i = 0; i <= mi; i++)
tmp[edg[i]] = 0;
}
pii ret = all[edg[lo]];
if (dp[ret.fi] < dp[ret.se])
swap(ret.fi, ret.se);
return ret.fi;
}
void find_pair(int N, vi U, vi V, int a, int b) {
n = N;
m = U.size();
for (int i = 0; i < m; i++) {
adj[U[i]].pb(mp(V[i],i));
adj[V[i]].pb(mp(U[i],i));
all.pb(mp(U[i], V[i]));
}
dist = ask(vi(m, 0));
int lo = 0, hi = n-1;
while (lo <= hi) {
int mi = (lo+hi) / 2;
vi tmp(m);
for (int i = 0; i <= mi; i++)
for (pii nx: adj[i])
tmp[nx.se] = 1;
ll w = ask(tmp);
if (w == dist)
lo = mi + 1;
else
hi = mi - 1;
}
//dist = -1;
int s = solve(lo);
int t = solve(s);
answer(s, t);
}
Compilation message
highway.cpp: In function 'int solve(int)':
highway.cpp:68:24: warning: unused variable 'ans' [-Wunused-variable]
int lo = 0, hi = n-1, ans = 0;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4856 KB |
Output is correct |
2 |
Correct |
6 ms |
4800 KB |
Output is correct |
3 |
Correct |
7 ms |
4856 KB |
Output is correct |
4 |
Correct |
6 ms |
4856 KB |
Output is correct |
5 |
Correct |
6 ms |
4796 KB |
Output is correct |
6 |
Correct |
6 ms |
4904 KB |
Output is correct |
7 |
Correct |
6 ms |
4984 KB |
Output is correct |
8 |
Correct |
6 ms |
4856 KB |
Output is correct |
9 |
Correct |
6 ms |
4904 KB |
Output is correct |
10 |
Correct |
6 ms |
4900 KB |
Output is correct |
11 |
Correct |
6 ms |
4904 KB |
Output is correct |
12 |
Correct |
6 ms |
4856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4856 KB |
Output is correct |
2 |
Correct |
29 ms |
5624 KB |
Output is correct |
3 |
Correct |
221 ms |
11736 KB |
Output is correct |
4 |
Correct |
228 ms |
11800 KB |
Output is correct |
5 |
Correct |
258 ms |
11740 KB |
Output is correct |
6 |
Correct |
248 ms |
11736 KB |
Output is correct |
7 |
Correct |
253 ms |
11736 KB |
Output is correct |
8 |
Correct |
240 ms |
11836 KB |
Output is correct |
9 |
Correct |
225 ms |
11736 KB |
Output is correct |
10 |
Correct |
222 ms |
11732 KB |
Output is correct |
11 |
Correct |
257 ms |
11184 KB |
Output is correct |
12 |
Correct |
252 ms |
11196 KB |
Output is correct |
13 |
Correct |
266 ms |
11192 KB |
Output is correct |
14 |
Correct |
247 ms |
11188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
5712 KB |
Output is correct |
2 |
Correct |
45 ms |
6384 KB |
Output is correct |
3 |
Correct |
70 ms |
6996 KB |
Output is correct |
4 |
Correct |
184 ms |
11292 KB |
Output is correct |
5 |
Correct |
198 ms |
11196 KB |
Output is correct |
6 |
Correct |
165 ms |
11236 KB |
Output is correct |
7 |
Correct |
210 ms |
11252 KB |
Output is correct |
8 |
Correct |
178 ms |
11176 KB |
Output is correct |
9 |
Correct |
190 ms |
11184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4856 KB |
Output is correct |
2 |
Correct |
29 ms |
5600 KB |
Output is correct |
3 |
Correct |
181 ms |
10460 KB |
Output is correct |
4 |
Correct |
264 ms |
11776 KB |
Output is correct |
5 |
Correct |
244 ms |
11744 KB |
Output is correct |
6 |
Correct |
253 ms |
11736 KB |
Output is correct |
7 |
Correct |
254 ms |
11772 KB |
Output is correct |
8 |
Correct |
257 ms |
11824 KB |
Output is correct |
9 |
Correct |
251 ms |
11772 KB |
Output is correct |
10 |
Correct |
254 ms |
11796 KB |
Output is correct |
11 |
Correct |
269 ms |
11184 KB |
Output is correct |
12 |
Correct |
229 ms |
11180 KB |
Output is correct |
13 |
Correct |
265 ms |
11192 KB |
Output is correct |
14 |
Correct |
274 ms |
11184 KB |
Output is correct |
15 |
Correct |
262 ms |
11728 KB |
Output is correct |
16 |
Correct |
268 ms |
11744 KB |
Output is correct |
17 |
Correct |
255 ms |
11196 KB |
Output is correct |
18 |
Correct |
267 ms |
11256 KB |
Output is correct |
19 |
Correct |
247 ms |
11744 KB |
Output is correct |
20 |
Correct |
264 ms |
11180 KB |
Output is correct |
21 |
Correct |
247 ms |
11884 KB |
Output is correct |
22 |
Correct |
304 ms |
11980 KB |
Output is correct |
23 |
Correct |
242 ms |
11884 KB |
Output is correct |
24 |
Correct |
203 ms |
11368 KB |
Output is correct |
25 |
Correct |
227 ms |
11280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
5716 KB |
Output is correct |
2 |
Correct |
31 ms |
5788 KB |
Output is correct |
3 |
Correct |
276 ms |
12212 KB |
Output is correct |
4 |
Correct |
317 ms |
12772 KB |
Output is correct |
5 |
Correct |
345 ms |
14012 KB |
Output is correct |
6 |
Correct |
363 ms |
14012 KB |
Output is correct |
7 |
Correct |
363 ms |
13948 KB |
Output is correct |
8 |
Correct |
369 ms |
13952 KB |
Output is correct |
9 |
Correct |
306 ms |
11868 KB |
Output is correct |
10 |
Correct |
218 ms |
12492 KB |
Output is correct |
11 |
Correct |
328 ms |
12744 KB |
Output is correct |
12 |
Correct |
353 ms |
13616 KB |
Output is correct |
13 |
Correct |
341 ms |
13792 KB |
Output is correct |
14 |
Correct |
325 ms |
14020 KB |
Output is correct |
15 |
Correct |
349 ms |
13928 KB |
Output is correct |
16 |
Correct |
269 ms |
13052 KB |
Output is correct |
17 |
Correct |
234 ms |
11964 KB |
Output is correct |
18 |
Correct |
247 ms |
12164 KB |
Output is correct |
19 |
Correct |
248 ms |
12072 KB |
Output is correct |
20 |
Correct |
236 ms |
12160 KB |
Output is correct |
21 |
Correct |
330 ms |
13608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
5732 KB |
Output is correct |
2 |
Correct |
28 ms |
5772 KB |
Output is correct |
3 |
Partially correct |
282 ms |
12268 KB |
Output is partially correct |
4 |
Correct |
271 ms |
12472 KB |
Output is correct |
5 |
Partially correct |
290 ms |
12760 KB |
Output is partially correct |
6 |
Correct |
349 ms |
13932 KB |
Output is correct |
7 |
Partially correct |
279 ms |
12252 KB |
Output is partially correct |
8 |
Correct |
279 ms |
12464 KB |
Output is correct |
9 |
Partially correct |
290 ms |
12892 KB |
Output is partially correct |
10 |
Partially correct |
340 ms |
13964 KB |
Output is partially correct |
11 |
Partially correct |
356 ms |
13940 KB |
Output is partially correct |
12 |
Correct |
354 ms |
13996 KB |
Output is correct |
13 |
Correct |
340 ms |
12740 KB |
Output is correct |
14 |
Correct |
275 ms |
12580 KB |
Output is correct |
15 |
Correct |
308 ms |
12824 KB |
Output is correct |
16 |
Correct |
261 ms |
12636 KB |
Output is correct |
17 |
Correct |
301 ms |
12808 KB |
Output is correct |
18 |
Correct |
266 ms |
12496 KB |
Output is correct |
19 |
Correct |
354 ms |
13660 KB |
Output is correct |
20 |
Partially correct |
354 ms |
13820 KB |
Output is partially correct |
21 |
Partially correct |
353 ms |
13944 KB |
Output is partially correct |
22 |
Partially correct |
368 ms |
13944 KB |
Output is partially correct |
23 |
Partially correct |
347 ms |
13972 KB |
Output is partially correct |
24 |
Partially correct |
373 ms |
13992 KB |
Output is partially correct |
25 |
Partially correct |
380 ms |
13948 KB |
Output is partially correct |
26 |
Partially correct |
352 ms |
13968 KB |
Output is partially correct |
27 |
Correct |
249 ms |
12208 KB |
Output is correct |
28 |
Partially correct |
258 ms |
12124 KB |
Output is partially correct |
29 |
Partially correct |
237 ms |
12160 KB |
Output is partially correct |
30 |
Correct |
273 ms |
12216 KB |
Output is correct |
31 |
Correct |
243 ms |
12136 KB |
Output is correct |
32 |
Partially correct |
229 ms |
11984 KB |
Output is partially correct |
33 |
Correct |
232 ms |
12244 KB |
Output is correct |
34 |
Correct |
212 ms |
12088 KB |
Output is correct |
35 |
Partially correct |
229 ms |
12172 KB |
Output is partially correct |
36 |
Partially correct |
265 ms |
11956 KB |
Output is partially correct |
37 |
Correct |
229 ms |
12300 KB |
Output is correct |
38 |
Partially correct |
226 ms |
12192 KB |
Output is partially correct |
39 |
Partially correct |
340 ms |
13600 KB |
Output is partially correct |
40 |
Partially correct |
328 ms |
13508 KB |
Output is partially correct |
41 |
Correct |
329 ms |
13548 KB |
Output is correct |
42 |
Correct |
328 ms |
13504 KB |
Output is correct |