제출 #201142

#제출 시각아이디문제언어결과실행 시간메모리
201142extraterrestrialMeetings (JOI19_meetings)C++14
29 / 100
3085 ms1916 KiB
#include "meetings.h"
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
mt19937 rnd(228);

const int N = 2010;
short up[N][20];
vector<short> have[N];
vector<pair<short, short>> pars[N];
short ptr[N], color[N];
int opers, opers2	;
bool was[N];

int get_color(int v) {
	if (color[v] != -1) {
		return color[v];
	}
	return color[v] = get_color(pars[v][ptr[v]].F);
}

vector<pair<short, short>> edge;

void Solve(int n) {
  short root = rnd() % n;
  for (int i = 0; i < n; i++) {
  	have[root].pb(i);
  }
  assert(n <= 2000);
  queue<short> q;
  q.push(root);
  while (!q.empty()) {
  	int root = q.front();
  	assert(!was[root]);
  	was[root] = true;
  	q.pop();
  	if (SZ(have[root]) == 1) {
  		continue;
  	}
  	for (int i = 0; i < SZ(have[root]); i++) {
  		color[have[root][i]] = -1;
  	}
		short cc = 0;
		for (short v : have[root]) {
			if (v == root) {
				continue;
			}
			while (ptr[v] < SZ(pars[v]) && was[pars[v][ptr[v]].S]) {
				ptr[v]++;
				opers2++;
			}
			if (ptr[v] < SZ(pars[v]) || color[v] != -1) {
				continue;
			}
			for (int j = 0; j < cc; j++) {
				opers++;
				short V = Query(root, up[root][j], v);
				if (V != root) {
					if (V != up[root][j]) pars[up[root][j]].pb({v, V});
					else pars[v].pb({up[root][j], V});
					up[root][j] = V;
					color[V] = j;
					color[v] = j;
					break;
				}
			}
			if (color[v] == -1) {
				up[root][cc] = v;
				color[v] = cc++;
			}
		}
		assert(opers <= (int)n * n);
		assert(opers2 <= (int)n * n);
		for (int i = 0; i < cc; i++) {
			edge.pb({root, up[root][i]});
		}
		for (short v : have[root]) {
			if (v != root) {
				have[up[root][get_color(v)]].pb(v);			
			}
		}
		for (int i = 0; i < cc; i++) {
			q.push(up[root][i]);	
		}	
  }
  for (auto &it : edge) {
  	if (it.F > it.S) {
  		swap(it.F, it.S);
  	}
  	Bridge(it.F, it.S);
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...