이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <vector>
#include <iostream>
#include <map>
#include "highway.h"
using namespace std;
int const MAXN=1e5;
vector<int>w;
long long dis=0;
vector<pair<int,int>>nei[MAXN]={};
int B1,A1;
vector<pair<int,int>>edges;
vector<int>ed[MAXN]={};
int h[MAXN]={};
int p[MAXN]={};
vector<int>d;
vector<int>g;
int it[MAXN],ot[MAXN];
int tm=0;
void dfs(int u,int pa=-1)
{
it[u]=tm++;
p[u]=pa;
for (auto [i,in]:nei[u])
{
if (i==pa)
continue;
ed[h[u]].push_back(in);
h[i]=h[u]+1;
dfs(i,u);
}
ot[u]=tm-1;
}
bool check(int mid)
{
for (int i=mid;i<MAXN;i++)
{
for (auto j:ed[i])
w[j]=1;
}
long long g=ask(w);
for (int i=mid;i<MAXN;i++)
{
for (auto j:ed[i])
w[j]=0;
}
return (g!=dis);
}
bool check1(int mid,int z)
{
for (int i=mid;i<MAXN;i++)
{
for (auto j:ed[i])
{
int x=edges[j].first;
if (it[x]<=it[z]&&ot[x]>=ot[z])
continue;
w[j]=1;
}
}
long long g=ask(w);
for (int i=mid;i<MAXN;i++)
{
for (auto j:ed[i])
w[j]=0;
}
return (g!=dis);
}
void divi(int st,int en)
{
if (st==en)
{
d.push_back(g[en]);
return;
}
int mid=(st+en)/2;
for (int i=st;i<=mid;i++)
w[g[i]]=1;
long long co=ask(w);
for (int i=st;i<=mid;i++)
w[g[i]]=0;
if (co>dis)
divi(st,mid);
for (int i=mid+1;i<=en;i++)
w[g[i]]=1;
co=ask(w);
for (int i=mid+1;i<=en;i++)
w[g[i]]=0;
if (co>dis)
divi(mid+1,en);
}
void find_pair(int N, vector<int> U, vector<int> V, int A, int B)
{
A1=A,B1=B;
int m=U.size();
for (int i=0;i<m;i++)
{
nei[U[i]].push_back({V[i],i});
nei[V[i]].push_back({U[i],i});
}
dfs(0);
for (int i=0;i<m;i++)
{
if (h[U[i]]>h[V[i]])
swap(U[i],V[i]);
edges.push_back({U[i],V[i]});
}
w.resize(m,0);
dis=ask(w);
h[0]=0;
int st=0,en=N;
while (st+1<en)
{
int mid=(st+en)/2;
if (check(mid))
st=mid;
else
en=mid;
}
for (auto i:ed[st])
g.push_back(i);
divi(0,g.size()-1);
if (d.size()==2)
answer(edges[d[0]].second,edges[d[1]].second);
else
{
en=st;
st=-1;
int z=edges[d[0]].second;
while (st+1<en)
{
int mid=(st+en)/2;
if (check1(mid,z))
st=mid;
else
en=mid;
}
if (st==-1)
{
int len=dis/A;
int x=z;
while (len--)
x=p[x];
answer(z,x);
return;
}
d={};
for (auto i:ed[st])
{
int x=edges[i].first;
if (it[x]<=it[z]&&ot[x]>=ot[z])
continue;
g.push_back(i);
}
divi(0,g.size()-1);
answer(z,edges[d[0]].second);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |