#include "highway.h"
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;
#define mp make_pair
#define pb emplace_back
#define f first
#define s second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound
vpi V[100100];
int sub[100100];
vi q;
int par[100100];
int rt;
int blk[100100];
int ban[100100];
int ind;
int dfs(int x, int p){
ban[x]=0;
if (blk[x])return 0;
par[x]=p;
sub[x] = 1;
for (auto i : V[x]){
if (i.f==par[x])continue;
sub[x] += dfs(i.f,x);
}
return sub[x];
}
void dfs2(int x, int p){
// cout<<"DFS2 "<<x<<' '<<p<<'\n';
for (auto i : V[x]){
q[i.s] =1;
if (i.f==par[x])continue;
dfs2(i.f,x);
}
}
void find_pair(int N, std::vector<int> U, std::vector<int> _V, int A, int B) {
int M = U.size();
q.resize(N-1,0);
for (int i=0;i<M;++i){
int a=_V[i];
int b=U[i];
V[a].pb(b,i);
V[b].pb(a,i);
}
dfs(0,-1);
int pos = N;
// for (auto i : q)cout<<i<<' ';cout<<'\n';
int len = ask(q);
// cout<<len<<'\n';
while (pos > 1){
// cout<<"Position "<<pos<<'\n';
ban[rt]=1;
int mindst = 1e9;
ind = 0;
for (int i=1;i<N;++i)if(!ban[i]){
if (abs(sub[rt] - 2*sub[i]) < mindst){
mindst = abs(sub[0] - 2*sub[i]);
ind = i;
}
}
for (int i=0;i<N;++i)q[i]=0;
// cout<<ind<<'\n';
dfs2(ind,par[ind]);
// for (auto i : q)cout<<i<<' ';cout<<'\n';
int t = ask(q);
if (t != len){
// cout<<"Reroot "<<ind<<'\n';
for (int i=0;i<N;++i)ban[i]=1;
dfs(ind, par[ind]);
pos = sub[ind];
rt = ind;
if (pos == 1){
answer(0,rt);
return;
}
}else{
// cout<<"NO Reroot\n";
for (int i=0;i<N;++i){ban[i]=1;sub[i]=0;}
blk[ind] = 1;
dfs(rt,par[rt]);
// for (int i=0;i<N;++i)cout<<sub[i]<<' ';cout<<'\n';
pos = sub[rt];
if (pos == 1){
answer(0,ind);
return;
}
}
}
answer(0,rt);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
2680 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
2684 KB |
Output is incorrect: more than 100 calls to ask. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
25 ms |
3832 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
2680 KB |
Output is incorrect: more than 100 calls to ask. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
427 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
396 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |