답안 #975310

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
975310 2024-05-04T18:19:23 Z raspy 슈퍼트리 잇기 (IOI20_supertrees) C++14
21 / 100
158 ms 22680 KB
#include "supertrees.h"
#include <vector>
#include <iostream>

using namespace std;

bool obd[20005];
int dis[20005];
vector<int> el[20005];

int par(int x)
{
	return dis[x] = (dis[x] == x ? x : par(dis[x]));
}

void zd(int x, int y, bool zlij = true)
{
	x = par(x);
	y = par(y);
	if (x == y)
		return;
	if (el[x].size() < el[y].size())
		swap(x, y);
	if (zlij)
	{
		for (auto e : el[y])
			el[x].push_back(e);
	}
	// el[y].clear();
	dis[y] = x;
	return;
}

int construct(vector<vector<int>> p)
{
	int n = p.size();
	vector<vector<int>> gr(n, vector<int>(n, 0));
	for (int i = 0; i <= n; i++)
	{
		el[i].push_back(i);
		dis[i] = i; 
	}
	for (int i = 0; i < n; i++)
		for (int j = i+1; j < n; j++)
		{
			if (p[i][j] == 1 && par(i)-par(j))
			{
				gr[par(i)][par(j)] = gr[par(j)][par(i)] = 1;
				zd(i, j, 0);
			}
		}
	int dalje = 0;
	for (int i = 0; i < n; i++)
		for (int j = i+1; j < n; j++)
		{
			if (p[i][j] == 2 && par(i)-par(j))
			{
				dalje = 1;
				zd(i, j);
			}
		}
	if (dalje)
	{
		for (int i = 0; i < n; i++)
		{
			int x = par(i);
			if (obd[x])
				continue;
			obd[x] = 1;			
			vector<int> tr = el[x];
			if (tr.size() <= 2)
				return 0;
			tr.push_back(x);
			int pr = -1;
			for (auto v : tr)
			{
				if (pr+1)
					gr[v][pr] = gr[pr][v] = 1;
				pr = v;
			}
		}
	}
	for (int i = 0; i < n; i++)
		for (int j = i+1; j < n; j++)
			if (p[i][j] == 0 && par(i) == par(j))
				return 0;
	build(gr);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 856 KB Output is correct
2 Correct 0 ms 1112 KB Output is correct
3 Correct 0 ms 860 KB Output is correct
4 Correct 0 ms 860 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 7 ms 1676 KB Output is correct
7 Correct 148 ms 22608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 856 KB Output is correct
2 Correct 0 ms 1112 KB Output is correct
3 Correct 0 ms 860 KB Output is correct
4 Correct 0 ms 860 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 7 ms 1676 KB Output is correct
7 Correct 148 ms 22608 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 0 ms 860 KB Output is correct
10 Correct 1 ms 1112 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 6 ms 1736 KB Output is correct
13 Correct 145 ms 22540 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 0 ms 860 KB Output is correct
16 Correct 3 ms 1372 KB Output is correct
17 Correct 62 ms 12628 KB Output is correct
18 Correct 1 ms 860 KB Output is correct
19 Correct 0 ms 860 KB Output is correct
20 Correct 37 ms 6240 KB Output is correct
21 Correct 147 ms 22612 KB Output is correct
22 Correct 152 ms 22516 KB Output is correct
23 Correct 149 ms 22516 KB Output is correct
24 Correct 151 ms 22500 KB Output is correct
25 Correct 59 ms 12628 KB Output is correct
26 Correct 60 ms 12628 KB Output is correct
27 Correct 150 ms 22680 KB Output is correct
28 Correct 144 ms 22612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 0 ms 860 KB Output is correct
3 Correct 0 ms 860 KB Output is correct
4 Correct 0 ms 860 KB Output is correct
5 Correct 0 ms 860 KB Output is correct
6 Correct 0 ms 860 KB Output is correct
7 Correct 0 ms 860 KB Output is correct
8 Correct 7 ms 1880 KB Output is correct
9 Correct 147 ms 22484 KB Output is correct
10 Correct 1 ms 856 KB Output is correct
11 Correct 1 ms 856 KB Output is correct
12 Correct 7 ms 1628 KB Output is correct
13 Correct 148 ms 22540 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 1 ms 1112 KB Output is correct
16 Correct 3 ms 1372 KB Output is correct
17 Correct 67 ms 12776 KB Output is correct
18 Correct 1 ms 856 KB Output is correct
19 Correct 1 ms 856 KB Output is correct
20 Incorrect 1 ms 860 KB Answer gives possible 0 while actual possible 1
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1112 KB Output is correct
2 Correct 0 ms 860 KB Output is correct
3 Correct 0 ms 860 KB Output is correct
4 Correct 38 ms 6228 KB Output is correct
5 Correct 146 ms 22496 KB Output is correct
6 Correct 144 ms 22496 KB Output is correct
7 Correct 158 ms 22616 KB Output is correct
8 Incorrect 1 ms 860 KB Answer gives possible 0 while actual possible 1
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 856 KB Output is correct
2 Correct 0 ms 1112 KB Output is correct
3 Correct 0 ms 860 KB Output is correct
4 Correct 0 ms 860 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 7 ms 1676 KB Output is correct
7 Correct 148 ms 22608 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 0 ms 860 KB Output is correct
10 Correct 1 ms 1112 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 6 ms 1736 KB Output is correct
13 Correct 145 ms 22540 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 0 ms 860 KB Output is correct
16 Correct 3 ms 1372 KB Output is correct
17 Correct 62 ms 12628 KB Output is correct
18 Correct 1 ms 860 KB Output is correct
19 Correct 0 ms 860 KB Output is correct
20 Correct 37 ms 6240 KB Output is correct
21 Correct 147 ms 22612 KB Output is correct
22 Correct 152 ms 22516 KB Output is correct
23 Correct 149 ms 22516 KB Output is correct
24 Correct 151 ms 22500 KB Output is correct
25 Correct 59 ms 12628 KB Output is correct
26 Correct 60 ms 12628 KB Output is correct
27 Correct 150 ms 22680 KB Output is correct
28 Correct 144 ms 22612 KB Output is correct
29 Correct 1 ms 860 KB Output is correct
30 Correct 0 ms 860 KB Output is correct
31 Correct 0 ms 860 KB Output is correct
32 Correct 0 ms 860 KB Output is correct
33 Correct 0 ms 860 KB Output is correct
34 Correct 0 ms 860 KB Output is correct
35 Correct 0 ms 860 KB Output is correct
36 Correct 7 ms 1880 KB Output is correct
37 Correct 147 ms 22484 KB Output is correct
38 Correct 1 ms 856 KB Output is correct
39 Correct 1 ms 856 KB Output is correct
40 Correct 7 ms 1628 KB Output is correct
41 Correct 148 ms 22540 KB Output is correct
42 Correct 1 ms 860 KB Output is correct
43 Correct 1 ms 1112 KB Output is correct
44 Correct 3 ms 1372 KB Output is correct
45 Correct 67 ms 12776 KB Output is correct
46 Correct 1 ms 856 KB Output is correct
47 Correct 1 ms 856 KB Output is correct
48 Incorrect 1 ms 860 KB Answer gives possible 0 while actual possible 1
49 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 856 KB Output is correct
2 Correct 0 ms 1112 KB Output is correct
3 Correct 0 ms 860 KB Output is correct
4 Correct 0 ms 860 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 7 ms 1676 KB Output is correct
7 Correct 148 ms 22608 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 0 ms 860 KB Output is correct
10 Correct 1 ms 1112 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 6 ms 1736 KB Output is correct
13 Correct 145 ms 22540 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 0 ms 860 KB Output is correct
16 Correct 3 ms 1372 KB Output is correct
17 Correct 62 ms 12628 KB Output is correct
18 Correct 1 ms 860 KB Output is correct
19 Correct 0 ms 860 KB Output is correct
20 Correct 37 ms 6240 KB Output is correct
21 Correct 147 ms 22612 KB Output is correct
22 Correct 152 ms 22516 KB Output is correct
23 Correct 149 ms 22516 KB Output is correct
24 Correct 151 ms 22500 KB Output is correct
25 Correct 59 ms 12628 KB Output is correct
26 Correct 60 ms 12628 KB Output is correct
27 Correct 150 ms 22680 KB Output is correct
28 Correct 144 ms 22612 KB Output is correct
29 Correct 1 ms 860 KB Output is correct
30 Correct 0 ms 860 KB Output is correct
31 Correct 0 ms 860 KB Output is correct
32 Correct 0 ms 860 KB Output is correct
33 Correct 0 ms 860 KB Output is correct
34 Correct 0 ms 860 KB Output is correct
35 Correct 0 ms 860 KB Output is correct
36 Correct 7 ms 1880 KB Output is correct
37 Correct 147 ms 22484 KB Output is correct
38 Correct 1 ms 856 KB Output is correct
39 Correct 1 ms 856 KB Output is correct
40 Correct 7 ms 1628 KB Output is correct
41 Correct 148 ms 22540 KB Output is correct
42 Correct 1 ms 860 KB Output is correct
43 Correct 1 ms 1112 KB Output is correct
44 Correct 3 ms 1372 KB Output is correct
45 Correct 67 ms 12776 KB Output is correct
46 Correct 1 ms 856 KB Output is correct
47 Correct 1 ms 856 KB Output is correct
48 Incorrect 1 ms 860 KB Answer gives possible 0 while actual possible 1
49 Halted 0 ms 0 KB -