이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
struct edge{
int to,id;
};
vector<edge>V[900000];
int dist[900000];
void dfs(int x,int from){
for(edge e:V[x]){
if(e.to==from)continue;
dist[e.to]=dist[x]+1;
dfs(e.to,x);
}
}
void find_pair(int N,vector<int>u,vector<int>v,int A,int B){
int M=u.size();
for(int i=0;i<M;i++){
V[u[i]].push_back({v[i],i});
V[v[i]].push_back({u[i],i});
}
long long Base=ask(vector<int>(M,0));
int path_len=Base/A;
int l,r;
l=-1;
r=M-1;
while(l+1!=r){
int m=(l+r)/2;
vector<int>K(M,0);
for(int i=0;i<=m;i++){
K[m]=1;
}
int t=ask(K);
if(t>Base){
r=m;
}
else{
l=m;
}
}
int p=u[r];
int q=v[r];
vector<int>K(M,0);
K[r]=1;
queue<int>que;
que.push(q);
while(!que.empty()){
int x=que.front();
que.pop();
for(edge e:V[x]){
if(K[e.id])continue;
K[e.id]=true;
que.push(e.to);
}
}
K[r]=0;
long long t=ask(K);
int len=(t-Base)/(B-A);
int S,T;
for(int i=0;i<N;i++){
dist[i]=-1;
}
dfs(q,p);
vector<int>W;
for(int i=0;i<N;i++){
if(dist[i]==len){
W.push_back(i);
}
}
l=-1;
r=W.size()-1;
while(l+1!=r){
int m=(l+r)/2;
vector<int>K(M,0);
for(int i=0;i<=m;i++){
for(edge e:V[i]){
K[e.id]=1;
}
}
if(Base!=ask(K)){
r=m;
}
else{
l=m;
}
}
S=W[r];
W.clear();
for(int i=0;i<N;i++){
dist[i]=-1;
}
dfs(p,q);
for(int i=0;i<N;i++){
if(dist[i]==path_len-1-len){
W.push_back(i);
}
}
l=-1;
r=W.size()-1;
while(l+1!=r){
int m=(l+r)/2;
vector<int>K(M,0);
for(int i=0;i<=m;i++){
for(edge e:V[i]){
K[e.id]=1;
}
}
if(Base!=ask(K)){
r=m;
}
else{
l=m;
}
}
T=W[r];
answer(S,T);
}
# | 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... |