답안 #162579

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
162579 2019-11-08T20:03:54 Z cerberus 로카히아 유적 (FXCUP4_lokahia) C++17
100 / 100
3 ms 632 KB
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include "lokahia.h"

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 2e2 + 10;

int par[N], sz[N];

int get_root(int u);
void merge(int u, int v);
int ask(int u, int v);

int FindBase(int n) {
	for (int i = 0; i < n; ++i) {
		par[i] = i;
		sz[i] = 1;
	}
	int u = -1, ctr = 0;
	for (int i = 0; i < n; ++i) {
		if (ctr == 0) {
			u = i;
			ctr = 1;
		} else {
			int l = ask(u, i);
			if (l == -1) {
				--ctr;
			} else {
				++ctr;
				merge(u, l);
				merge(i, l);
			}
		}
	}
	for (int i = 0; i < n; ++i) {
		if (par[i] == i) {
			int v = ask(u, i);
			if (v != -1) {
				merge(u, v);
				merge(i, v);
			}
		}
	}
	u = get_root(u);
	if (sz[u] > n / 2) {
		return u;
	} else {
		return -1;
	}
}

int get_root(int u) {
	if (par[u] != u) {
		par[u] = get_root(par[u]);
	}
	return par[u];
}

void merge(int u, int v) {
	u = get_root(u);
	v = get_root(v);
	if (u != v) {
		par[u] = v;
		sz[v] += sz[u];
	}
}

int ask(int u, int v) {
	u = get_root(u);
	v = get_root(v);
	if (u == v) {
		return u;
	} else {
		return CollectRelics(u, v);
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 632 KB Correct : C = 294
2 Correct 2 ms 504 KB Correct : C = 0
3 Correct 3 ms 628 KB Correct : C = 293
4 Correct 3 ms 632 KB Correct : C = 197
5 Correct 2 ms 632 KB Correct : C = 172
6 Correct 3 ms 632 KB Correct : C = 288
7 Correct 2 ms 504 KB Correct : C = 176
8 Correct 2 ms 628 KB Correct : C = 281
9 Correct 2 ms 504 KB Correct : C = 117
10 Correct 3 ms 632 KB Correct : C = 291
11 Correct 2 ms 504 KB Correct : C = 173
12 Correct 3 ms 504 KB Correct : C = 281
13 Correct 3 ms 632 KB Correct : C = 198
14 Correct 2 ms 504 KB Correct : C = 170
15 Correct 2 ms 504 KB Correct : C = 174
16 Correct 3 ms 632 KB Correct : C = 295
17 Correct 2 ms 632 KB Correct : C = 118
18 Correct 2 ms 444 KB Correct : C = 4
19 Correct 2 ms 632 KB Correct : C = 171
20 Correct 2 ms 504 KB Correct : C = 299
21 Correct 3 ms 504 KB Correct : C = 290
22 Correct 2 ms 632 KB Correct : C = 177
23 Correct 2 ms 632 KB Correct : C = 179
24 Correct 2 ms 632 KB Correct : C = 282
25 Correct 3 ms 632 KB Correct : C = 289
26 Correct 2 ms 632 KB Correct : C = 297
27 Correct 2 ms 632 KB Correct : C = 293