#include "highway.h"
#include <bits/stdc++.h>
//#include "grader.cpp"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
mt19937 rng(chrono::steady_clock().now().time_since_epoch().count());
int n,m,niv[100005],par[100005],topar[100005],dp[21][100005],in[100005],out[100005],timp,roots[5];
ll dist,AA,BB,d[3][100005];
vector<int> muchii[100005];
vector<pii> g;
vector<int> w;
ll memo[100005],calls;
void bfs(int ind)
{
for(int i=0;i<n;i++)
d[ind][i]=1e9;
d[ind][roots[ind]]=0;
queue<int> coada;
coada.push(roots[ind]);
while(!coada.empty())
{
int nod=coada.front();
coada.pop();
for(int i:muchii[nod])
if(d[ind][i]>d[ind][nod]+1)
{
d[ind][i]=d[ind][nod]+1;
coada.push(i);
}
}
}
bool good[100005],mark[100005];
ll firstsearch(ll ind,ll nivmax)
{
for(int i=0;i<m;i++)
{
ll a=g[i].first;
ll b=g[i].second;
if(d[ind][a]<d[ind][b])
swap(a,b);
if(good[a]&&d[ind][a]<=nivmax)
w[i]=1;
else
w[i]=0;
}
return ask(w);
}
ll secondsearch(ll ind)
{
for(int i=0;i<m;i++)
{
ll a=g[i].first;
ll b=g[i].second;
if(d[ind][a]<d[ind][b])
swap(a,b);
if(mark[a])
w[i]=1;
w[i]=0;
}
return ask(w);
}
int plsfind(int ind)
{
int u=roots[ind];
ll nivmax=0;
for(int i=0;i<n;i++)
{
good[i]=0;
if(d[ind][i]<d[3-ind][i])
{
nivmax=max(nivmax,d[ind][i]);
good[i]=1;
}
}
int myniv=0;
int st=0;
int dr=nivmax;
while(st<=dr)
{
int mij=(st+dr)/2;
ll val=firstsearch(ind,mij);
if(mij<=dist&&val==(dist-mij)*AA+mij*BB)
{
myniv=mij;
st=mij+1;
}
else
dr=mij-1;
}
vector<int> cand;
for(int i=0;i<n;i++)
if(good[i]&&d[ind][i]==myniv)
cand.push_back(i);
while(true)
{
if(cand.size()==1)
return cand[0];
vector<int> x;
vector<int> y;
int lg=cand.size();
for(int i=0;i<cand.size();i++)
{
if(i<lg/2)
x.push_back(cand[i]);
else
y.push_back(cand[i]);
}
for(int i=0;i<n;i++)
mark[i]=0;
for(int i:x)
mark[i]=1;
ll val=secondsearch(ind);
if(val>dist*AA)
cand=x;
else
cand=y;
}
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B)
{
AA=A;
BB=B;
n=N;
m=U.size();
for(int i=0;i<m;i++)
{
int a=U[i],b=V[i];
g.push_back({a,b});
muchii[a].push_back(b);
muchii[b].push_back(a);
}
w.resize(m);
dist=ask(w)/A;
ll st=0;
ll dr=m-1;
while(st<=dr)
{
ll mij=(st+dr)/2;
for(int i=0;i<n;i++)
{
if(i<=mij)
w[i]=1;
else
w[i]=0;
}
ll val=ask(w);
if(val>dist*A)
{
roots[1]=g[mij].first;
roots[2]=g[mij].second;
dr=mij-1;
}
else
st=mij+1;
}
bfs(1);
bfs(2);
int S=plsfind(1);
int T=plsfind(2);
answer(S,T);
}
Compilation message
highway.cpp: In function 'int plsfind(int)':
highway.cpp:102:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
102 | for(int i=0;i<cand.size();i++)
| ~^~~~~~~~~~~~
highway.cpp:65:9: warning: unused variable 'u' [-Wunused-variable]
65 | int u=roots[ind];
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
6624 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
6672 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
7256 KB |
Output is correct |
2 |
Correct |
17 ms |
8148 KB |
Output is correct |
3 |
Correct |
40 ms |
8384 KB |
Output is correct |
4 |
Correct |
80 ms |
12132 KB |
Output is correct |
5 |
Correct |
74 ms |
12140 KB |
Output is correct |
6 |
Correct |
66 ms |
11988 KB |
Output is correct |
7 |
Correct |
110 ms |
12092 KB |
Output is correct |
8 |
Correct |
92 ms |
11964 KB |
Output is correct |
9 |
Correct |
115 ms |
11964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
6664 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
16 ms |
7268 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
7332 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |