//#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 = 90050;
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;
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 s = solve(0);
int t = solve(s);
answer(s, t);
}
Compilation message
highway.cpp: In function 'int solve(int)':
highway.cpp:67:24: warning: unused variable 'ans' [-Wunused-variable]
int lo = 0, hi = n-1, ans = 0;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
3576 KB |
Output is correct |
2 |
Correct |
5 ms |
3372 KB |
Output is correct |
3 |
Correct |
5 ms |
3468 KB |
Output is correct |
4 |
Correct |
5 ms |
3448 KB |
Output is correct |
5 |
Correct |
6 ms |
3368 KB |
Output is correct |
6 |
Correct |
6 ms |
3496 KB |
Output is correct |
7 |
Correct |
4 ms |
3448 KB |
Output is correct |
8 |
Correct |
5 ms |
3448 KB |
Output is correct |
9 |
Correct |
5 ms |
3448 KB |
Output is correct |
10 |
Correct |
5 ms |
3368 KB |
Output is correct |
11 |
Correct |
5 ms |
3448 KB |
Output is correct |
12 |
Correct |
5 ms |
3464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
3448 KB |
Output is correct |
2 |
Correct |
26 ms |
4224 KB |
Output is correct |
3 |
Correct |
222 ms |
10328 KB |
Output is correct |
4 |
Correct |
202 ms |
10328 KB |
Output is correct |
5 |
Correct |
219 ms |
10408 KB |
Output is correct |
6 |
Correct |
197 ms |
10420 KB |
Output is correct |
7 |
Correct |
231 ms |
10328 KB |
Output is correct |
8 |
Correct |
229 ms |
10416 KB |
Output is correct |
9 |
Correct |
219 ms |
10324 KB |
Output is correct |
10 |
Correct |
225 ms |
10300 KB |
Output is correct |
11 |
Correct |
248 ms |
9772 KB |
Output is correct |
12 |
Correct |
243 ms |
9772 KB |
Output is correct |
13 |
Correct |
253 ms |
9772 KB |
Output is correct |
14 |
Correct |
217 ms |
9780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
4044 KB |
Output is correct |
2 |
Correct |
41 ms |
4916 KB |
Output is correct |
3 |
Correct |
61 ms |
5572 KB |
Output is correct |
4 |
Correct |
164 ms |
9768 KB |
Output is correct |
5 |
Correct |
171 ms |
9776 KB |
Output is correct |
6 |
Correct |
175 ms |
9772 KB |
Output is correct |
7 |
Correct |
168 ms |
9844 KB |
Output is correct |
8 |
Correct |
174 ms |
9772 KB |
Output is correct |
9 |
Correct |
162 ms |
9760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
3528 KB |
Output is correct |
2 |
Correct |
47 ms |
4140 KB |
Output is correct |
3 |
Correct |
177 ms |
8992 KB |
Output is correct |
4 |
Correct |
196 ms |
10324 KB |
Output is correct |
5 |
Correct |
233 ms |
10412 KB |
Output is correct |
6 |
Correct |
233 ms |
10324 KB |
Output is correct |
7 |
Correct |
221 ms |
10340 KB |
Output is correct |
8 |
Correct |
223 ms |
10452 KB |
Output is correct |
9 |
Correct |
230 ms |
10348 KB |
Output is correct |
10 |
Correct |
249 ms |
10412 KB |
Output is correct |
11 |
Correct |
257 ms |
9824 KB |
Output is correct |
12 |
Correct |
239 ms |
9812 KB |
Output is correct |
13 |
Correct |
223 ms |
9772 KB |
Output is correct |
14 |
Correct |
227 ms |
9780 KB |
Output is correct |
15 |
Correct |
219 ms |
10408 KB |
Output is correct |
16 |
Correct |
218 ms |
10404 KB |
Output is correct |
17 |
Correct |
220 ms |
9920 KB |
Output is correct |
18 |
Correct |
247 ms |
9776 KB |
Output is correct |
19 |
Correct |
219 ms |
10340 KB |
Output is correct |
20 |
Correct |
257 ms |
9772 KB |
Output is correct |
21 |
Correct |
226 ms |
10472 KB |
Output is correct |
22 |
Correct |
177 ms |
10528 KB |
Output is correct |
23 |
Correct |
179 ms |
10544 KB |
Output is correct |
24 |
Correct |
177 ms |
10008 KB |
Output is correct |
25 |
Correct |
225 ms |
9884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
4312 KB |
Output is correct |
2 |
Correct |
25 ms |
4388 KB |
Output is correct |
3 |
Correct |
257 ms |
11000 KB |
Output is correct |
4 |
Correct |
271 ms |
11420 KB |
Output is correct |
5 |
Incorrect |
320 ms |
12540 KB |
Output is incorrect: {s, t} is wrong. |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
27 ms |
4428 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |