답안 #319146

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
319146 2020-11-04T08:46:18 Z Drew_ 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
284 ms 26068 KB
#include "supertrees.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define f1 first
#define s2 second

using ii = pair<int, int>;


int const N = 1007;

int ds[N];

int frep(int x)
{
	return ds[x] == x ? x : ds[x] = frep(ds[x]);
}

void join(int x, int y)
{
	x = frep(x); y = frep(y);
	if (x == y)
		return;
	ds[y] = x; //x is parent of y
}

int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	for (int i = 0; i < n; ++i)
		ds[i] = i;

	vector<ii> disconnected;
	for (int i = 0; i < n; ++i)
	{
		for (int j = i+1; j < n; ++j)
		{
			if (p[i][j] == 0)
			{
				disconnected.pb({i, j});
				continue;
			}

			if (p[i][j] == 3)
			{
				return 0;
			}

			join(i, j);
		}
	}

	for (ii x : disconnected)
	{
		if (frep(x.f1) == frep(x.s2))
			return 0;
	}

	vector<vector<int>> graph (n);
	vector<vector<int>> _b (n, vector<int> (n, 0));

	for (int i = 0; i < n; ++i)
		graph[frep(i)].pb(i);

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

	for (auto g : graph)
	{
		if (g.empty())
			continue;

		for (int i = 0; i < g.size(); ++i)
			for (int j = i+1; j < g.size(); ++j)
		{
			if (p[g[i]][g[j]] == 1)
				join(g[i], g[j]);

			else if (frep(g[i]) == frep(g[j]))
				return 0;
		}

		set<int> st;
		for (int i = 0; i < g.size(); ++i)
		{
			cerr << frep(g[i]) << " - " << g[i] << '\n';
			_b[frep(g[i])][g[i]] = _b[g[i]][frep(g[i])] = 1;
			st.insert(frep(g[i]));
		}

		if (st.size() == 1)
			continue;

		if (st.size() == 2)
			return 0;

		vector<int> node;
		for (int x : st)
			node.pb(x);
		node.pb(*st.begin());

		for (int i = 0; i+1 < node.size(); ++i)
			cerr << node[i] << " -- " << node[i+1] << '\n',
			_b[node[i]][node[i+1]] = _b[node[i+1]][node[i]] = true;
	}

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

	build(_b);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:75:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |   for (int i = 0; i < g.size(); ++i)
      |                   ~~^~~~~~~~~~
supertrees.cpp:76:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |    for (int j = i+1; j < g.size(); ++j)
      |                      ~~^~~~~~~~~~
supertrees.cpp:86:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |   for (int i = 0; i < g.size(); ++i)
      |                   ~~^~~~~~~~~~
supertrees.cpp:104:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |   for (int i = 0; i+1 < node.size(); ++i)
      |                   ~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 372 KB Output is correct
6 Correct 12 ms 1260 KB Output is correct
7 Correct 253 ms 24036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 372 KB Output is correct
6 Correct 12 ms 1260 KB Output is correct
7 Correct 253 ms 24036 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 14 ms 1404 KB Output is correct
13 Correct 262 ms 26068 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 5 ms 924 KB Output is correct
17 Correct 108 ms 12508 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 69 ms 6744 KB Output is correct
21 Correct 274 ms 25680 KB Output is correct
22 Correct 266 ms 26060 KB Output is correct
23 Correct 269 ms 24092 KB Output is correct
24 Correct 263 ms 26068 KB Output is correct
25 Correct 113 ms 14424 KB Output is correct
26 Correct 107 ms 14424 KB Output is correct
27 Correct 278 ms 24096 KB Output is correct
28 Correct 266 ms 26068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 13 ms 1384 KB Output is correct
9 Correct 268 ms 26068 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 14 ms 1260 KB Output is correct
13 Correct 259 ms 24164 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 5 ms 876 KB Output is correct
17 Correct 108 ms 12380 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 73 ms 6744 KB Output is correct
22 Correct 274 ms 25680 KB Output is correct
23 Correct 274 ms 26040 KB Output is correct
24 Correct 277 ms 24144 KB Output is correct
25 Correct 113 ms 18132 KB Output is correct
26 Correct 111 ms 14424 KB Output is correct
27 Correct 272 ms 26060 KB Output is correct
28 Correct 284 ms 24092 KB Output is correct
29 Correct 114 ms 18132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 396 KB Output is correct
4 Correct 77 ms 6744 KB Output is correct
5 Correct 266 ms 25552 KB Output is correct
6 Correct 266 ms 25932 KB Output is correct
7 Correct 269 ms 24092 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 74 ms 6744 KB Output is correct
10 Correct 282 ms 25680 KB Output is correct
11 Correct 270 ms 25932 KB Output is correct
12 Correct 278 ms 24228 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 73 ms 6872 KB Output is correct
17 Correct 268 ms 25676 KB Output is correct
18 Correct 271 ms 25656 KB Output is correct
19 Correct 269 ms 25932 KB Output is correct
20 Correct 259 ms 26068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 372 KB Output is correct
6 Correct 12 ms 1260 KB Output is correct
7 Correct 253 ms 24036 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 14 ms 1404 KB Output is correct
13 Correct 262 ms 26068 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 5 ms 924 KB Output is correct
17 Correct 108 ms 12508 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 69 ms 6744 KB Output is correct
21 Correct 274 ms 25680 KB Output is correct
22 Correct 266 ms 26060 KB Output is correct
23 Correct 269 ms 24092 KB Output is correct
24 Correct 263 ms 26068 KB Output is correct
25 Correct 113 ms 14424 KB Output is correct
26 Correct 107 ms 14424 KB Output is correct
27 Correct 278 ms 24096 KB Output is correct
28 Correct 266 ms 26068 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 13 ms 1384 KB Output is correct
37 Correct 268 ms 26068 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 14 ms 1260 KB Output is correct
41 Correct 259 ms 24164 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 5 ms 876 KB Output is correct
45 Correct 108 ms 12380 KB Output is correct
46 Correct 1 ms 492 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 73 ms 6744 KB Output is correct
50 Correct 274 ms 25680 KB Output is correct
51 Correct 274 ms 26040 KB Output is correct
52 Correct 277 ms 24144 KB Output is correct
53 Correct 113 ms 18132 KB Output is correct
54 Correct 111 ms 14424 KB Output is correct
55 Correct 272 ms 26060 KB Output is correct
56 Correct 284 ms 24092 KB Output is correct
57 Correct 114 ms 18132 KB Output is correct
58 Correct 1 ms 364 KB Output is correct
59 Correct 1 ms 364 KB Output is correct
60 Correct 5 ms 876 KB Output is correct
61 Correct 123 ms 12380 KB Output is correct
62 Correct 1 ms 364 KB Output is correct
63 Correct 1 ms 364 KB Output is correct
64 Correct 1 ms 364 KB Output is correct
65 Correct 90 ms 6744 KB Output is correct
66 Correct 111 ms 14420 KB Output is correct
67 Correct 109 ms 14424 KB Output is correct
68 Correct 106 ms 14444 KB Output is correct
69 Correct 118 ms 18132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 372 KB Output is correct
6 Correct 12 ms 1260 KB Output is correct
7 Correct 253 ms 24036 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 14 ms 1404 KB Output is correct
13 Correct 262 ms 26068 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 5 ms 924 KB Output is correct
17 Correct 108 ms 12508 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 69 ms 6744 KB Output is correct
21 Correct 274 ms 25680 KB Output is correct
22 Correct 266 ms 26060 KB Output is correct
23 Correct 269 ms 24092 KB Output is correct
24 Correct 263 ms 26068 KB Output is correct
25 Correct 113 ms 14424 KB Output is correct
26 Correct 107 ms 14424 KB Output is correct
27 Correct 278 ms 24096 KB Output is correct
28 Correct 266 ms 26068 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 13 ms 1384 KB Output is correct
37 Correct 268 ms 26068 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 14 ms 1260 KB Output is correct
41 Correct 259 ms 24164 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 5 ms 876 KB Output is correct
45 Correct 108 ms 12380 KB Output is correct
46 Correct 1 ms 492 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 73 ms 6744 KB Output is correct
50 Correct 274 ms 25680 KB Output is correct
51 Correct 274 ms 26040 KB Output is correct
52 Correct 277 ms 24144 KB Output is correct
53 Correct 113 ms 18132 KB Output is correct
54 Correct 111 ms 14424 KB Output is correct
55 Correct 272 ms 26060 KB Output is correct
56 Correct 284 ms 24092 KB Output is correct
57 Correct 114 ms 18132 KB Output is correct
58 Correct 1 ms 492 KB Output is correct
59 Correct 1 ms 364 KB Output is correct
60 Correct 1 ms 396 KB Output is correct
61 Correct 77 ms 6744 KB Output is correct
62 Correct 266 ms 25552 KB Output is correct
63 Correct 266 ms 25932 KB Output is correct
64 Correct 269 ms 24092 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 74 ms 6744 KB Output is correct
67 Correct 282 ms 25680 KB Output is correct
68 Correct 270 ms 25932 KB Output is correct
69 Correct 278 ms 24228 KB Output is correct
70 Correct 1 ms 364 KB Output is correct
71 Correct 1 ms 364 KB Output is correct
72 Correct 1 ms 364 KB Output is correct
73 Correct 73 ms 6872 KB Output is correct
74 Correct 268 ms 25676 KB Output is correct
75 Correct 271 ms 25656 KB Output is correct
76 Correct 269 ms 25932 KB Output is correct
77 Correct 259 ms 26068 KB Output is correct
78 Correct 1 ms 364 KB Output is correct
79 Correct 1 ms 364 KB Output is correct
80 Correct 5 ms 876 KB Output is correct
81 Correct 123 ms 12380 KB Output is correct
82 Correct 1 ms 364 KB Output is correct
83 Correct 1 ms 364 KB Output is correct
84 Correct 1 ms 364 KB Output is correct
85 Correct 90 ms 6744 KB Output is correct
86 Correct 111 ms 14420 KB Output is correct
87 Correct 109 ms 14424 KB Output is correct
88 Correct 106 ms 14444 KB Output is correct
89 Correct 118 ms 18132 KB Output is correct
90 Correct 1 ms 364 KB Output is correct
91 Correct 1 ms 364 KB Output is correct
92 Correct 5 ms 748 KB Output is correct
93 Correct 96 ms 10192 KB Output is correct
94 Correct 1 ms 364 KB Output is correct
95 Correct 1 ms 364 KB Output is correct
96 Correct 1 ms 364 KB Output is correct
97 Correct 27 ms 3172 KB Output is correct
98 Correct 101 ms 10956 KB Output is correct
99 Correct 100 ms 11360 KB Output is correct
100 Correct 99 ms 11488 KB Output is correct
101 Correct 103 ms 14424 KB Output is correct
102 Correct 88 ms 10216 KB Output is correct
103 Correct 90 ms 10208 KB Output is correct
104 Correct 87 ms 10212 KB Output is correct
105 Correct 99 ms 10212 KB Output is correct