Submission #131493

#TimeUsernameProblemLanguageResultExecution timeMemory
131493ekremMeetings (JOI19_meetings)C++14
29 / 100
3075 ms3832 KiB

#include "meetings.h"
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define inf 1000000009
#define MAXN 1000005

using namespace std;

typedef long long ll;
typedef pair < int , int > ii;
typedef set < int > si;

int n, k, sil[MAXN];
si :: iterator it;

int sor(int x, int y, int z){
	if(x == y)return x;
	if(z == y)return z;
	if(x == z)return x;
	return Query(x - 1, y - 1, z - 1) + 1;
}

void coz(si a, int x){
	if(a.empty())
		return;
	si b;
	int son = *a.begin();
	b.insert(son);
	a.erase(son);
	k = 0;
	// cout << x << " -> " << son << " ";
	for(it = a.begin(); it != a.end(); it++){
		// cout << *it << " ";
		int y = sor(son, x, *it);
		// cout << son << " " << x << " " << *it << " = " << y << endl;
		if(y == x)
			continue;
		if(y == son){
			sil[++k] = *it;
			// it = a.erase(y);
			b.insert(*it);
			continue;
		}
		son = y;
		sil[++k] = y;
		sil[++k] = *it;
		// it = a.erase(y);
		b.insert(y);
		b.insert(*it);
	}
	// cout << endl;
	for(int i = 1; i <= k; i++)
		a.erase(sil[i]);
	Bridge(min(x - 1, son - 1), max(x - 1, son - 1));
	// cout << x << " " << son << " " << b.size() << endl;
	b.erase(son);
	coz(b, son);
	coz(a, x);
}

void Solve(int nn) {n = nn;
	si a;
	for(int i = 2; i <= n; i++)
		a.insert(i);
	coz(a, 1);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...