#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef double ld;
typedef complex<ld> point;
void debug_out(){cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
cerr << H << ' ';
debug_out(T...);
}
#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)
const int maxn = 1e5 + 10;
int n, m, h[maxn], par[maxn], edge[maxn][2], cnt;
vector<int> g[maxn];
vector<int> cand;
ll query1(int x){
cnt++;
if (cnt > 60) assert(0);
//debug(x);
vector<int> q(m, 0);
for (int i = 0; i < n; i++){
if (h[i] >= x) q[par[i]] = 1;
}
//for (int i = 0; i < m; i++) debug(i, q[i]);
return ask(q);
}
ll query2(int x){
cnt++;
if (cnt > 60) assert(0);
//debug(x);
vector<int> q(m, 0);
for (int i = 0; i <= x; i++){
q[par[cand[i]]] = 1;
}
//debug()
return ask(q);
}
void dfs(int v, int x = -1){
par[v] = x;
//debug(v, h[v], par[v]);
for (auto i: g[v]){
if (i == x) continue;
int u = edge[i][0]^edge[i][1]^v;
h[u] = h[v] + 1;
dfs(u, i);
}
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
n = N;
m = U.size();
for (int i = 0; i < m; i++){
edge[i][0] = U[i];
edge[i][1] = V[i];
g[U[i]].push_back(i);
g[V[i]].push_back(i);
}
dfs(0);
int mx = max_element(h, h+n) - h;
ll dis = query1(n);
//debug(dis);
int l = 0, r = h[mx]+1;
while(l + 1 < r){
int mid = (l + r) >> 1;
if (query1(mid) > dis) l = mid;
else r = mid;
}
//debug(l);
for (int i = 0; i < n; i++) if (h[i] == l) cand.push_back(i);
//for (auto x: cand) debug(x);
l = -1, r = cand.size() - 1;
while(l + 1 < r){
int mid = (l + r) >> 1;
if (query2(mid) > dis) r = mid;
else l = mid;
}
int r1 = cand[r];
//debug(r1);
h[r1] = 0;
dfs(r1);
mx = max_element(h, h+n) - h;
l = 0, r = h[mx]+1;
while(l + 1 < r){
int mid = (l + r) >> 1;
if (query1(mid) > dis) l = mid;
else r = mid;
}
//debug(l);
cand.clear();
for (int i = 0; i < n; i++) if (h[i] == l) cand.push_back(i);
l = -1, r = cand.size() - 1;
while(l + 1 < r){
int mid = (l + r) >> 1;
if (query2(mid) > dis) r = mid;
else l = mid;
}
int r2 = cand[r];
//debug(r2);
answer(r1, r2);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
1 ms |
2640 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Correct |
1 ms |
2640 KB |
Output is correct |
8 |
Correct |
2 ms |
2640 KB |
Output is correct |
9 |
Correct |
2 ms |
2640 KB |
Output is correct |
10 |
Correct |
1 ms |
2640 KB |
Output is correct |
11 |
Correct |
1 ms |
2640 KB |
Output is correct |
12 |
Correct |
1 ms |
2640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2640 KB |
Output is correct |
2 |
Correct |
12 ms |
3340 KB |
Output is correct |
3 |
Correct |
105 ms |
8872 KB |
Output is correct |
4 |
Correct |
80 ms |
8872 KB |
Output is correct |
5 |
Correct |
100 ms |
8872 KB |
Output is correct |
6 |
Correct |
101 ms |
8900 KB |
Output is correct |
7 |
Correct |
109 ms |
8864 KB |
Output is correct |
8 |
Correct |
88 ms |
8876 KB |
Output is correct |
9 |
Correct |
95 ms |
8944 KB |
Output is correct |
10 |
Correct |
124 ms |
8868 KB |
Output is correct |
11 |
Correct |
124 ms |
10356 KB |
Output is correct |
12 |
Correct |
124 ms |
11344 KB |
Output is correct |
13 |
Correct |
122 ms |
10520 KB |
Output is correct |
14 |
Correct |
127 ms |
10652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
4048 KB |
Output is correct |
2 |
Correct |
15 ms |
5560 KB |
Output is correct |
3 |
Correct |
35 ms |
7088 KB |
Output is correct |
4 |
Correct |
76 ms |
15756 KB |
Output is correct |
5 |
Correct |
122 ms |
15696 KB |
Output is correct |
6 |
Correct |
67 ms |
15688 KB |
Output is correct |
7 |
Correct |
94 ms |
15756 KB |
Output is correct |
8 |
Correct |
89 ms |
15692 KB |
Output is correct |
9 |
Correct |
63 ms |
15692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
10 ms |
3280 KB |
Output is correct |
3 |
Correct |
57 ms |
7472 KB |
Output is correct |
4 |
Correct |
110 ms |
8816 KB |
Output is correct |
5 |
Correct |
76 ms |
8816 KB |
Output is correct |
6 |
Correct |
93 ms |
8936 KB |
Output is correct |
7 |
Correct |
107 ms |
8864 KB |
Output is correct |
8 |
Correct |
100 ms |
8880 KB |
Output is correct |
9 |
Correct |
114 ms |
8880 KB |
Output is correct |
10 |
Correct |
99 ms |
8868 KB |
Output is correct |
11 |
Correct |
105 ms |
10292 KB |
Output is correct |
12 |
Correct |
99 ms |
11208 KB |
Output is correct |
13 |
Correct |
119 ms |
10680 KB |
Output is correct |
14 |
Correct |
139 ms |
11136 KB |
Output is correct |
15 |
Correct |
100 ms |
8812 KB |
Output is correct |
16 |
Correct |
68 ms |
8808 KB |
Output is correct |
17 |
Correct |
148 ms |
10892 KB |
Output is correct |
18 |
Correct |
131 ms |
10980 KB |
Output is correct |
19 |
Correct |
88 ms |
8800 KB |
Output is correct |
20 |
Correct |
128 ms |
11732 KB |
Output is correct |
21 |
Correct |
77 ms |
9520 KB |
Output is correct |
22 |
Correct |
100 ms |
9512 KB |
Output is correct |
23 |
Correct |
109 ms |
9512 KB |
Output is correct |
24 |
Correct |
114 ms |
10240 KB |
Output is correct |
25 |
Runtime error |
128 ms |
30268 KB |
Execution killed with signal 6 |
26 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
187 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
182 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |