Submission #201146

#TimeUsernameProblemLanguageResultExecution timeMemory
201146extraterrestrialMeetings (JOI19_meetings)C++14
17 / 100
1242 ms1868 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];

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

void Solve(int n) {
  short root = 0;
  for (int i = 0; i < n; i++) {
  	have[root].pb(i);
  }
  queue<short> q;
  q.push(root);
  while (!q.empty()) {
  	short root = q.front();
  	was[root] = true;
  	q.pop();
  	if (SZ(have[root]) == 1) {
  		continue;
  	}
  	for (short v : have[root]) {
  		color[v] = -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]++;
			}
			if (ptr[v] < SZ(pars[v]) || color[v] != -1) {
				continue;
			}
			for (short j = 0; j < cc; j++) {
				short V = Query(root, up[root][j], v);
				opers++;
				assert(opers <= 40000);
				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++;
			}
		}
		for (int i = 0; i < cc; i++) {
			Bridge(min(root, up[root][i]), max(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]);	
		}	
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...