#include "highway.h"
#include <cstdio>
#include <cassert>
const int MN = 9e4+10;
const int MM = 1.3e5+10;
using ll = long long;
struct edg
{
public:
int n, i;
};
std::vector<edg> a[MN];
int pre[MN], ctr, pid[MN], ord[MN], d[MN], post[MN];
void dfs(int n, int p=-1)
{
ord[ctr] = n;
pre[n]=ctr++;
for(int i=0;i<(int)a[n].size();++i)
{
if(a[n][i].n == p)
{
a[n].erase(a[n].begin()+i);
--i;
continue;
}
d[a[n][i].n]=d[n]+1;
pid[a[n][i].n]=a[n][i].i;
dfs(a[n][i].n, n);
}
post[n]=ctr;
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
int M = U.size();
for(int i=0;i<M;++i)
{
a[U[i]].push_back({V[i], i});
a[V[i]].push_back({U[i], i});
}
std::vector<int> w(M, 0);
ll dist_raw = ask(w); // -1
int dist = (int)(dist_raw/A);
dfs(0);
assert(ctr == N);
int lca=-1;
{ // -17
int l=0, r=N;
for(;r-l>1;)
{
int m=l+(r-l)/2;
w.assign(M, 0);
for(int i=l;i<m;++i)
for(auto x:a[ord[i]])
w[x.i]=1;
if(ask(w)>dist_raw)
r = m;
else
l = m;
}
lca=ord[l];
}
int S;
{ // -17
int l=pre[lca]+1;
int r=post[lca];
for(;r-l>1;)
{
int m=l+(r-l)/2;
w.assign(M, 0);
for(int i=m;i<r;++i)
w[pid[ord[i]]]=1;
//printf("%d %d %d %lld\n", ord[l], ord[m], ord[r], ask(w));
if(ask(w)>dist_raw)
l = m;
else
r = m;
//printf("%d %d\n", l, r);
}
S = ord[l];
}
int T;
{ // -17
std::vector<int> cand;
for(int i=pre[lca];i<pre[S];++i)
if(d[ord[i]] + d[S] - 2*d[lca] == dist)
cand.push_back(ord[i]);
int l=0, r=cand.size(); // can binsearch from left or right now
for(;r-l>1;)
{
int m=l+(r-l)/2;
w.assign(M, 0);
for(int i=l;i<m;++i)
w[pid[cand[i]]]=1;
if(ask(w) > dist_raw)
r = m;
else
l = m;
}
T = cand[l];
}
//printf("%d %d\n", S, T);
answer(S, T);
}
# |
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 |
4 ms |
2376 KB |
Output is correct |
4 |
Correct |
5 ms |
2372 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 |
2388 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 |
2376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2468 KB |
Output is correct |
2 |
Correct |
15 ms |
3144 KB |
Output is correct |
3 |
Correct |
138 ms |
9296 KB |
Output is correct |
4 |
Correct |
154 ms |
9276 KB |
Output is correct |
5 |
Correct |
134 ms |
9316 KB |
Output is correct |
6 |
Correct |
146 ms |
9276 KB |
Output is correct |
7 |
Correct |
149 ms |
9276 KB |
Output is correct |
8 |
Correct |
139 ms |
9272 KB |
Output is correct |
9 |
Correct |
142 ms |
9292 KB |
Output is correct |
10 |
Correct |
142 ms |
9280 KB |
Output is correct |
11 |
Correct |
160 ms |
9752 KB |
Output is correct |
12 |
Correct |
153 ms |
10204 KB |
Output is correct |
13 |
Correct |
153 ms |
9848 KB |
Output is correct |
14 |
Correct |
163 ms |
9436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
3528 KB |
Output is correct |
2 |
Correct |
23 ms |
4720 KB |
Output is correct |
3 |
Correct |
36 ms |
5824 KB |
Output is correct |
4 |
Correct |
123 ms |
12952 KB |
Output is correct |
5 |
Correct |
115 ms |
12956 KB |
Output is correct |
6 |
Correct |
111 ms |
12864 KB |
Output is correct |
7 |
Correct |
109 ms |
12880 KB |
Output is correct |
8 |
Correct |
105 ms |
12868 KB |
Output is correct |
9 |
Correct |
112 ms |
12884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2376 KB |
Output is correct |
2 |
Correct |
16 ms |
3172 KB |
Output is correct |
3 |
Correct |
92 ms |
7784 KB |
Output is correct |
4 |
Correct |
146 ms |
9292 KB |
Output is correct |
5 |
Correct |
135 ms |
9276 KB |
Output is correct |
6 |
Correct |
140 ms |
9280 KB |
Output is correct |
7 |
Correct |
131 ms |
9404 KB |
Output is correct |
8 |
Correct |
144 ms |
9268 KB |
Output is correct |
9 |
Correct |
152 ms |
9352 KB |
Output is correct |
10 |
Correct |
141 ms |
9312 KB |
Output is correct |
11 |
Correct |
135 ms |
9396 KB |
Output is correct |
12 |
Correct |
134 ms |
10300 KB |
Output is correct |
13 |
Correct |
145 ms |
9920 KB |
Output is correct |
14 |
Correct |
140 ms |
10228 KB |
Output is correct |
15 |
Correct |
130 ms |
9288 KB |
Output is correct |
16 |
Correct |
139 ms |
9340 KB |
Output is correct |
17 |
Correct |
144 ms |
10108 KB |
Output is correct |
18 |
Correct |
139 ms |
9728 KB |
Output is correct |
19 |
Correct |
134 ms |
9284 KB |
Output is correct |
20 |
Correct |
155 ms |
10700 KB |
Output is correct |
21 |
Correct |
124 ms |
9864 KB |
Output is correct |
22 |
Correct |
129 ms |
10208 KB |
Output is correct |
23 |
Correct |
136 ms |
9844 KB |
Output is correct |
24 |
Correct |
137 ms |
10304 KB |
Output is correct |
25 |
Correct |
148 ms |
12360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
37 ms |
23788 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
37 ms |
24460 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |