제출 #418657

#제출 시각아이디문제언어결과실행 시간메모리
418657alishahali1382Park (JOI17_park)C++14
67 / 100
492 ms716 KiB
#include "park.h"
#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const int inf=1000000010;
const ll INF=1000000000000001000LL;
const int mod=1000000007;
const int MAXN=1510, LOG=18;

static int Place[1400];
inline int ask(int u, int v){
	if (u>v) swap(u, v);
	Place[u]=Place[v]=1;
	return Ask(u, v, Place);
}
inline void add_edge(int u, int v){
	if (u>v) swap(u, v);
	Answer(u, v);
}

int n, m, k, u, v, x, y, a, b, t;
int mark[MAXN];
int par[MAXN], h[MAXN];
vector<int> topol;
vector<int> G[MAXN];

void dfs(int node){
	topol.pb(node);
	for (int v:G[node]) dfs(v);
}
int GetPar(int v){
	int dwn=0, up=topol.size();
	while (up-dwn>1){
		int mid=(dwn+up)>>1;
		memset(Place, 0, sizeof(Place));
		for (int i=0; i<mid; i++) Place[topol[i]]=1;
		if (ask(0, v)) up=mid;
		else dwn=mid;
	}
	par[v]=topol[dwn];
	h[v]=h[par[v]]+1;
	return par[v];
}
int GetUp(int v){
	vector<int> bad;
	for (int i=0; i<n; i++) if (i!=v && !mark[i]) bad.pb(i);
	int dwn=0, up=bad.size();
	while (up-dwn>1){
		int mid=(dwn+up)>>1;
		memcpy(Place, mark, sizeof(Place));
		for (int i=0; i<mid; i++) Place[bad[i]]=1;
		if (ask(0, v)) up=mid;
		else dwn=mid;
	}
	return bad[dwn];
}


void Detect(int T, int _n){
	assert(T==2 || T==3 || T==4);
	n=_n;
	mark[0]=1;
	topol.pb(0);
	vector<int> vec;
	for (int i=1; i<n; i++) if (!mark[i]){
		vec.pb(i);
		while (vec.size()){
			// debugv(vec)
			int v=vec.back();
			memcpy(Place, mark, sizeof(Place));
			if (ask(0, v)){
				add_edge(GetPar(v), v);
				vec.pop_back();
				mark[v]=1;
				topol.pb(v);
				sort(all(topol), [](int i, int j){
					return h[i]<h[j];
				});
			}
			else{
				vec.pb(GetUp(v));
			}
		}
	}

}
#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...