이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#ifndef SKY
#include "highway.h"
#endif // SKY
using namespace std;
#define N 200010
#define ll long long
#define fs first
#define sc second
#define ii pair<int,int>
#define pb push_back
int times,ktr[N],root[2],cha[N][21],n,m,depth[N],par_id[N];
ll A,B;
ii canh[N],cnt[N];
vector<ii>g[N],ke[N];
queue<int>dq;
#ifdef SKY
int S_ans,T_ans;
void answer(int s,int t)
{
cout<<s<<" "<<t<<endl;
}
ll dis[55][55];
ll ask(vector<int>w)
{
memset(dis,0x3f3f,sizeof(dis));
for(int i=0;i<m;i++)
dis[canh[i].fs][canh[i].sc]=dis[canh[i].sc][canh[i].fs]=(w[i]==0 ? A : B);
for(int k=0;k<n;k++)
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
return dis[S_ans][T_ans];
}
#endif // SKY
int query;
ll my_ask(vector<int>w)
{
// assert(w.size()==m);
//assert(++query<=50);
return ask(w);
}
void DFS(int u,int p)
{
cnt[u].fs=++times;
for(auto v:g[u])
if(v.fs!=p)
{
par_id[v.fs]=v.sc;
depth[v.fs]=depth[u]+1;
cha[v.fs][0]=u;
DFS(v.fs,u);
}
cnt[u].sc=times;
}
bool tren(int u,int v)
{
return (cnt[u].fs<=cnt[v].fs&&cnt[u].sc>=cnt[v].sc);
}
bool SS(const int&u,const int&v)
{
return depth[u]<depth[v];
}
int solve(int id,ll val,int cs)
{
vector<int>s;
for(int i=0;i<n;i++)
if(i!=root[0]&&i!=root[1]&&tren(root[id],i))
s.pb(i);
sort(s.begin(),s.end(),SS);
// cout<<id<<endl;
//for(auto u:s)cout<<u<<" ";cout<<endl;
int res=root[id],l=0,r=s.size()-1;
while(l<=r)
{
int mid=(l+r)/2;
vector<int>hoi(m,1);
hoi[cs]=0;
for(int i=0;i<n;i++)
if(i!=root[0]&&i!=root[1]&&!tren(root[id],i))
hoi[par_id[i]]=0;
for(int i=0;i<=mid;i++)
hoi[par_id[s[i]]]=0;
// cout<<my_ask(hoi)<<endl;
if(my_ask(hoi)==val)
{
res=s[mid];
r=mid-1;
}else
l=mid+1;
}
return res;
}
void find_pair(int cc, vector<int> canh_fs, vector<int> canh_sc, int AAA, int BBB)
{
n=cc;
m=canh_fs.size();
A=AAA;
B=BBB;
for(int i=0;i<m;i++)
{
canh[i]={canh_fs[i],canh_sc[i]};
ke[canh[i].fs].pb({canh[i].sc,i});
ke[canh[i].sc].pb({canh[i].fs,i});
}
ll val=my_ask(vector<int>(m,0));
vector<int>s;
for(int i=0;i<m;i++)
s.pb(i);
while(s.size()>1)
{
vector<int>L,R;
for(int i=0;i<s.size();i++)
if(i*2<s.size())
L.pb(s[i]);
else R.pb(s[i]);
vector<int>hoi(m,0);
for(int i=0;i<=L.back();i++)
hoi[i]=1;
if(my_ask(hoi)!=val)
s=L;
else s=R;
}
//cout<<canh[s[0]].fs<<" "<<canh[s[0]].sc<<endl;
root[0]=canh[s[0]].fs;
root[1]=canh[s[0]].sc;
//cout<<root[0]<<" "<<root[1]<<endl;
queue<int>dq;
ktr[root[0]]=ktr[root[1]]=1;
dq.push(root[0]);
dq.push(root[1]);
while(!dq.empty())
{
int u=dq.front();
dq.pop();
for(auto v:ke[u])
if(ktr[v.fs]==0)
{
ktr[v.fs]=1;
dq.push(v.fs);
g[u].pb(v);
// cout<<u<<" "<<v.fs<<endl;
}
}
DFS(root[0],-1);
DFS(root[1],-1);
answer(solve(0,val,s[0]),solve(1,val,s[0]));
}
#ifdef SKY
int main()
{
freopen("A.inp","r",stdin);
freopen("A.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
srand(time(0));
int n,m,A,B;
map<int,int>mp[110];
cin>>n>>m>>S_ans>>T_ans>>A>>B;
vector<int>u(m),v(m);
for(int i=0;i<m;i++)
cin>>u[i]>>v[i];
/* for(int i=0;i<n-1;i++)
{
u[i]=i+1;
v[i]=rand()%(i+1);
mp[min(u[i],v[i])][max(u[i],v[i])]++;
}
for(int i=n-1;i<m;i++)
{
u[i]=rand()%n;
do{
v[i]=rand()%n;
}while(u[i]==v[i]||mp[min(u[i],v[i])][max(u[i],v[i])]!=0);
assert(u[i]!=v[i]);
mp[min(u[i],v[i])][max(u[i],v[i])]++;
}*/
// for(int i=0;i<m;i++)cout<<u[i]<<" "<<v[i]<<endl;
find_pair(n,u,v,A,B);
return 0;
}
#endif
컴파일 시 표준 에러 (stderr) 메시지
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:127:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
127 | for(int i=0;i<s.size();i++)
| ~^~~~~~~~~
highway.cpp:128:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
128 | if(i*2<s.size())
| ~~~^~~~~~~~~
# | 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... |