이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
// macros
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a : b)
#define all(a) a.begin(), a.end()
#define pb push_back
#define popb pop_back
#define fi first
#define se second
const int MX = 2e5;
int n, m;
vi U, V, W;
vi adj[MX];
ll normal;
vi seq;
bitset<MX> visited;
int dst[MX];
int minLB, maxUB;
void fillAdj() {
RE(i,U.size()) {
adj[U[i]].push_back(i);
adj[V[i]].push_back(i);
}
}
void bfsSequence(vi init, int dist=-1) {
minLB = -1, maxUB = -1;
queue<int> q;
visited.reset();
FOR(u,init) q.push(u), visited[u]=1, dst[u]=0;
while(!q.empty()) {
int u=q.front(); q.pop();
FOR(e,adj[u]) {
if(visited[U[e]] && visited[V[e]]) continue;
if(V[e] == u) swap(U[e], V[e]);
int v=V[e];
seq.push_back(e);
q.push(v); visited[v] = 1;
dst[v] = dst[u]+1;
if(dst[v] == dist && minLB == -1) minLB = seq.size()-1;
if(dst[v] == dist) maxUB = seq.size()-1;
}
}
if(dist == -1) minLB=0, maxUB=m-1;
}
int binarySearchSeq() {
int lb=minLB, ub=maxUB;
while(lb != ub) {
int mid=(lb+ub)/2;
W.assign(m,1);
REP(i,0,mid+1) W[seq[i]] = 0;
if(ask(W) == normal) ub=mid;
else lb=mid+1;
}
return V[seq[lb]];
}
int getEdgeOnPath() {
int lb=0, ub=m-1;
while(lb != ub) {
int mid=(lb+ub)/2;
W.assign(m,0);
RE(i,mid+1) W[i] = 1;
if(ask(W) == normal) lb=mid+1;
else ub=mid;
}
return lb;
}
void find_pair(int N, vi _U, vi _V, int A, int B) {
n=N; U=_U; V=_V; m=U.size();
fillAdj();
W.assign(m,0);
normal = ask(W);
int onPath = getEdgeOnPath();
int v1 = U[onPath], v2 = V[onPath];
seq.clear(); seq.push_back(onPath);
bfsSequence({v1, v2});
int s = binarySearchSeq();
seq.clear(); bfsSequence({s}, normal/ll(A));
int t = binarySearchSeq();
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... |