답안 #150130

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
150130 2019-09-01T07:46:36 Z お前はもう死んでいる(#3784, kuroni, nvmdava, tfg) 로카히아 유적 (FXCUP4_lokahia) C++17
0 / 100
13 ms 896 KB
#include "lokahia.h"
#include <bits/stdc++.h>
using namespace std;

const int N = 205;

random_device rd;
mt19937_64 mt(rd());

int n, dsu[N], con[N][N];
vector<int> ve[N];

int rand(int l, int r)
{
	uniform_int_distribution<int> uni(l, r);
	return uni(mt);
}

int trace(int u)
{
	return dsu[u] < 0 ? u : dsu[u] = trace(dsu[u]);
}

int connect(int u, int v)
{
	if ((u = trace(u)) == (v = trace(v)))
		return -1;
	if (dsu[u] > dsu[v])
		swap(u, v);
	dsu[u] += dsu[v];
	dsu[v] = u;
	vector<int> tmp;
	for (int j = 1; j <= n; j++)
		if (con[u][j] == -1 || con[v][j] == -1)
			tmp.push_back(j);
	for (int &a : ve[u])
		for (int &b : ve[v])
			con[a][b] = con[b][a] = 1;
	for (int &b : ve[v])
		ve[u].push_back(b);
	ve[v].clear();
	for (int &a : ve[u])
		for (int &b : tmp)
			con[a][b] = con[b][a] = -1;
	if (-dsu[u] >= n / 2)
		return u;
	return -1;
}

int FindBase(int _n)
{
	n = _n;
	for (int i = 0; i < n; i++)
	{
		dsu[i] = -1;
		ve[i] = {i};
		con[i][i] = 1;
	}
	for (int i = 1; i <= 600; i++)
	{
		int u, v, cnt = 0;
		do
		{
			u = rand(0, n - 1);
			v = rand(0, n - 1);
			cnt++;
		} while (con[u][v] != 0 && cnt <= 10);
		if (cnt > 10)
			break;
		u = trace(u); v = trace(v);
		int rt = CollectRelics(u, v);
		if (rt == -1)
		{
			for (int &a : ve[u])
				for (int &b : ve[v])
					con[a][b] = con[b][a] = -1;
		}
		else
		{
			connect(rt, u);
			int tmp = connect(rt, v);
			if (tmp >= 0)
				return tmp;
		}
	}
	for (int i = 0; i < n; i++)
		if (-dsu[i] >= n / 2)
			return i;
	return -1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 768 KB Correct : C = 264
2 Correct 6 ms 640 KB Correct : C = 39
3 Incorrect 12 ms 768 KB Wrong
4 Correct 7 ms 640 KB Correct : C = 37
5 Incorrect 13 ms 768 KB Wrong
6 Partially correct 9 ms 768 KB Partially correct : C = 511
7 Incorrect 7 ms 640 KB Wrong
8 Incorrect 6 ms 640 KB Wrong
9 Partially correct 10 ms 768 KB Partially correct : C = 332
10 Correct 5 ms 512 KB Correct : C = 0
11 Correct 7 ms 768 KB Correct : C = 65
12 Incorrect 10 ms 876 KB Wrong
13 Correct 9 ms 768 KB Correct : C = 242
14 Correct 7 ms 728 KB Correct : C = 213
15 Partially correct 6 ms 896 KB Partially correct : C = 600
16 Partially correct 9 ms 768 KB Partially correct : C = 514
17 Partially correct 5 ms 640 KB Partially correct : C = 600
18 Incorrect 10 ms 768 KB Wrong
19 Incorrect 7 ms 640 KB Wrong
20 Incorrect 7 ms 640 KB Wrong
21 Partially correct 6 ms 640 KB Partially correct : C = 600
22 Correct 7 ms 768 KB Correct : C = 60
23 Correct 13 ms 768 KB Correct : C = 188
24 Correct 7 ms 640 KB Correct : C = 203
25 Partially correct 6 ms 768 KB Partially correct : C = 600
26 Correct 6 ms 560 KB Correct : C = 2
27 Correct 9 ms 768 KB Correct : C = 240