이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "highway.h"
#define f first
#define ss second
#define pb push_back
#define mp make_pair
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
#define N 90005
vector<int> caras,especiais;
vector<pii> grafo[N], tree[N];
int pai[N], n, m, id_pai[N],A,B, dist_st;
void dfs(int x, int p){
pai[x]=p;
caras.pb(x);
for(auto v: tree[x]){
if(v.f == p) continue;
id_pai[v.f] =v.ss;
dfs(v.f, x);
}
}
int get(int root){
caras.clear();
dfs(root,root);
int ini = 1, fim = sz(caras)-1,mid,best=-1;
while(fim >=ini){
mid = (ini + fim)/2;
vector<int> w(m);
for(int i=0;i<m;i++)w[i]=1;
for(int i = 0; i <sz(especiais); i++) w[especiais[i]]=0;
for(int i = 1; i <= mid; i++) w[id_pai[caras[i]]] = 1;
int dmid = ask(w);
if(dmid == B*dist_st){
best=mid;
fim=mid-1;
}else ini=mid+1;
}
return caras[best];
}
void find_pair(int N_, std::vector<int> U, std::vector<int> V, int AA, int BB) {
n=N_;A=AA;B=BB;m=sz(U);
for(int i = 0; i < sz(U); i++){
grafo[U[i]].pb({V[i],i}); grafo[V[i]].pb({U[i],i});
}
vector<int>w(m);
dist_st = ask(w)/A;
int ini = 0, fim = m-1,mid,root=-1;
while(fim>=ini){
mid=(ini+fim)/2;
vector<int> w(m);
for(int i = 0; i < m; i++) w[i]=1;
for(int i = 0; i <= mid; i++) w[i]=0;
if(ask(w) != A*dist_st){
root = U[mid];
break;
}
else ini=mid+1;
}
assert(root!=-1);
vector<int>vis(n);
queue<int>fila;
fila.push(root); vis[root]=1;
while(!fila.empty()){
int x=fila.front();fila.pop();
for(auto v: grafo[x]){
if(!vis[v.f]){
vis[v.f]=1;
fila.push(v.f);
tree[x].pb(v);
tree[v.f].pb({x,v.ss});
especiais.pb(v.ss);
}
}
}
int S = get(root);
int T = get(S);
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... |