답안 #301567

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
301567 2020-09-18T04:39:20 Z jwvg0425 슈퍼트리 잇기 (IOI20_supertrees) C++17
56 / 100
875 ms 22264 KB
#include "supertrees.h"
#include <vector>
#include <set>

using namespace std;

int cpar[1005];
int tpar[1005];
vector<int> byTree[1005];

int tfind(int x)
{
	if (tpar[x] == x)
		return x;

	return tpar[x] = tfind(tpar[x]);
}

void tmerge(int x, int y)
{
	x = tfind(x);
	y = tfind(y);

	tpar[x] = y;
}

int cfind(int x)
{
	if (cpar[x] == x)
		return x;

	return cpar[x] = cfind(cpar[x]);
}

void cmerge(int x, int y)
{
	x = cfind(x);
	y = cfind(y);

	cpar[x] = y;
}

int construct(vector<vector<int>> p)
{
	int n = p.size();

	for (int i = 0; i < n; i++)
		cpar[i] = tpar[i] = i;

	vector<vector<int>> answer;
	for (int i = 0; i < n; i++)
	{
		vector<int> row;
		row.resize(n);
		answer.push_back(row);
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			if (p[i][j] == 0)
				continue;

			if (p[i][j] == 1)
			{
				if (tfind(i) == tfind(j))
					continue;

				tmerge(i, j);
				answer[i][j] = answer[j][i] = 1;
				continue;
			}

			if (p[i][j] == 2)
				cmerge(i, j);
		}
	}

	for (int i = 0; i < n; i++)
	{
		byTree[tfind(i)].push_back(i);

		for (int j = 0; j < n; j++)
		{
			if (p[i][j] != 0)
				continue;

			if (cfind(i) == cfind(j) || tfind(i) == tfind(j))
				return 0;
		}
	}

	for (int i = 0; i < n; i++)
	{
		if (cfind(i) != i)
			continue;

		vector<int> cs;
		set<int> ts;

		for (int j = 0; j < n; j++)
		{
			if (cfind(j) != i)
				continue;

			cs.push_back(j);
			ts.insert(tfind(j));
		}

		vector<int> tv;
		for (auto ti : ts)
		{
			tv.push_back(ti);

			for (auto &x : byTree[ti])
				for (auto &y : byTree[ti])
					if (p[x][y] != 1)
						return 0;

			for (auto &tj : ts)
			{
				if (ti == tj)
					continue;

				for (auto &x : byTree[ti])
					for (auto &y : byTree[tj])
						if (p[x][y] != 2)
							return 0;
			}
		}

		int k = tv.size();

		if (k < 2)
			continue;

		for (int x = 0; x < k; x++)
		{
			int nx = (x + 1) % k;
			answer[tv[x]][tv[nx]] = answer[tv[nx]][tv[x]] = 1;
		}
	}

	build(answer);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 16 ms 1280 KB Output is correct
7 Correct 875 ms 22120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 16 ms 1280 KB Output is correct
7 Correct 875 ms 22120 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 10 ms 1280 KB Output is correct
13 Correct 238 ms 22120 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 5 ms 768 KB Output is correct
17 Correct 108 ms 12152 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 62 ms 5880 KB Output is correct
21 Correct 264 ms 22136 KB Output is correct
22 Correct 242 ms 22136 KB Output is correct
23 Correct 435 ms 22140 KB Output is correct
24 Correct 245 ms 22136 KB Output is correct
25 Correct 100 ms 12152 KB Output is correct
26 Correct 93 ms 12152 KB Output is correct
27 Correct 435 ms 22264 KB Output is correct
28 Correct 239 ms 22264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Incorrect 1 ms 384 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 63 ms 5880 KB Output is correct
5 Correct 262 ms 22136 KB Output is correct
6 Correct 245 ms 22136 KB Output is correct
7 Correct 435 ms 22136 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 61 ms 6008 KB Output is correct
10 Correct 243 ms 22264 KB Output is correct
11 Correct 244 ms 22136 KB Output is correct
12 Correct 268 ms 22136 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 63 ms 6136 KB Output is correct
17 Correct 244 ms 22264 KB Output is correct
18 Correct 263 ms 22136 KB Output is correct
19 Correct 251 ms 22136 KB Output is correct
20 Correct 242 ms 22264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 16 ms 1280 KB Output is correct
7 Correct 875 ms 22120 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 10 ms 1280 KB Output is correct
13 Correct 238 ms 22120 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 5 ms 768 KB Output is correct
17 Correct 108 ms 12152 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 62 ms 5880 KB Output is correct
21 Correct 264 ms 22136 KB Output is correct
22 Correct 242 ms 22136 KB Output is correct
23 Correct 435 ms 22140 KB Output is correct
24 Correct 245 ms 22136 KB Output is correct
25 Correct 100 ms 12152 KB Output is correct
26 Correct 93 ms 12152 KB Output is correct
27 Correct 435 ms 22264 KB Output is correct
28 Correct 239 ms 22264 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Incorrect 1 ms 384 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 16 ms 1280 KB Output is correct
7 Correct 875 ms 22120 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 10 ms 1280 KB Output is correct
13 Correct 238 ms 22120 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 5 ms 768 KB Output is correct
17 Correct 108 ms 12152 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 62 ms 5880 KB Output is correct
21 Correct 264 ms 22136 KB Output is correct
22 Correct 242 ms 22136 KB Output is correct
23 Correct 435 ms 22140 KB Output is correct
24 Correct 245 ms 22136 KB Output is correct
25 Correct 100 ms 12152 KB Output is correct
26 Correct 93 ms 12152 KB Output is correct
27 Correct 435 ms 22264 KB Output is correct
28 Correct 239 ms 22264 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Incorrect 1 ms 384 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -