Submission #250954

#TimeUsernameProblemLanguageResultExecution timeMemory
250954ryansee통행료 (IOI18_highway)C++14
100 / 100
395 ms14176 KiB
#include "highway.h"

#include "bits/stdc++.h"
using namespace std;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long; 
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; 

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (100006)
vector<pi>v[MAXN];
void find_pair(int n, std::vector<int> U, std::vector<int> V, int A, int B) {
	int m=U.size();
	FOR(i,0,m-1){
		v[U[i]].eb(V[i],i);
		v[V[i]].eb(U[i],i);
	}
	vector<int> W(m,0), pe(n,0), vis(n,0), dist(n,0), XY(n,0);
	ll init=ask(W);//, len=init/A;
	ll st=-1, en=m-1;
	while(en-st>1){
		ll mid=(st+en)>>1;
		fill(all(W),0);
		FOR(i,0,mid)W[i]=1;
		if(ask(W)>init)en=mid;
		else st=mid;
	}
	ll x=U[en],y=V[en];
	queue<ll> q;
	q.emplace(x), q.emplace(y), vis[x]=vis[y]=1, dist[x]=dist[y]=0, XY[y]=1, pe[x]=pe[y]=en;
	while(q.size()){
		ll x=q.front();
		q.pop();
		for(auto i:v[x]) if(!vis[i.f]) {
			pe[i.f]=i.s, vis[i.f]=1, dist[i.f]=dist[x]+1, XY[i.f]=XY[x];
			q.emplace(i.f);
		} else assert(dist[i.f]<=dist[x]+1);
	}FOR(i,0,n-1)assert(vis[i]);
	vector<int> ppl;
	FOR(i,0,n-1)if(XY[i]==0)ppl.eb(i);
	sort(all(ppl),[&](int x,int y){return dist[x]<dist[y];});
	st=-1,en=siz(ppl)-1;
	while(en-st>1){
		ll mid=(st+en)>>1;
		fill(all(W),1);
		FOR(i,0,mid)W[pe[ppl[i]]]=0;
		FOR(i,0,n-1)if(XY[i])W[pe[i]]=0;
		if(ask(W)==init)en=mid;
		else st=mid;
	}en=ppl[en];
	ll ans=en;
	ppl.clear();
	FOR(i,0,n-1)if(XY[i])ppl.eb(i);
	sort(all(ppl),[&](int x,int y){return dist[x]<dist[y];});
	st=-1,en=siz(ppl)-1;
	while(en-st>1){
		ll mid=(st+en)>>1;
		fill(all(W),1);
		FOR(i,0,mid)W[pe[ppl[i]]]=0;
		FOR(i,0,n-1)if(XY[i]==0)W[pe[i]]=0;
		if(ask(W)==init)en=mid;
		else st=mid;
	}en=ppl[en];
	return answer(ans,en);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...