Submission #201141

#TimeUsernameProblemLanguageResultExecution timeMemory
201141extraterrestrialMeetings (JOI19_meetings)C++14
29 / 100
3078 ms1752 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 timer, up[N][20];
vector<short> nh[20], have[N];
vector<pair<short, short>> pars[N];
short ptr[N], color[N], skip[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 id = (have[root][0] == root ? 1 : 0);
		short cc = 1;
		nh[0] = {have[root][id]};
		up[root][0] = have[root][id];
		color[have[root][id]] = 0;
		timer++;
		for (int i = id + 1; i < SZ(have[root]); i++) {
			if (have[root][i] == root) {
				continue;
			}
			while (ptr[have[root][i]] < SZ(pars[have[root][i]]) && was[pars[have[root][i]][ptr[have[root][i]]].S]) {
				ptr[have[root][i]]++;
				opers2++;
			}
			if (ptr[have[root][i]] < SZ(pars[have[root][i]]) || color[have[root][i]] != -1) {
				skip[have[root][i]] = timer;
				continue;
			}
			for (int j = 0; j < cc; j++) {
				opers++;
				short v = Query(root, up[root][j], have[root][i]);
				if (v != root) {
					if (v != up[root][j]) pars[up[root][j]].pb({have[root][i], v});
					else pars[have[root][i]].pb({up[root][j], v});
					up[root][j] = v;
					nh[j].pb(have[root][i]);
					color[v] = j;
					color[have[root][i]] = j;
					break;
				}
			}
			if (color[have[root][i]] == -1) {
				nh[cc] = {have[root][i]};
				up[root][cc] = have[root][i];
				color[have[root][i]] = 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 (int i = 0; i < SZ(have[root]); i++) {
			if (have[root][i] != root && skip[have[root][i]] == timer) {
				get_color(have[root][i]);
				nh[color[have[root][i]]].pb(have[root][i]);
			}
		}
		for (int i = 0; i < cc; i++) {
			/*for (int j = 0; j < sz_nh[i]; j++) {
				have[up[root][i]][j] = nh[i][j];
			}
			sz_have[up[root][i]] = sz_nh[i];*/
			have[up[root][i]].swap(nh[i]);
		}
		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...