답안 #795142

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
795142 2023-07-27T07:00:09 Z adrilen 슈퍼트리 잇기 (IOI20_supertrees) C++17
56 / 100
206 ms 28020 KB
#include "supertrees.h"
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using arr = array<int, 2>;
using arrr = array<int, 3>;

constexpr int maxn = 1e3 + 5;

int next_group = 1;
int groups[maxn] = { 0 }, gnode[maxn] = { 0 }, siz[maxn] = { 0 };
bool done[maxn] = { 0 };

vector <int> adj[maxn];


int construct(std::vector<std::vector<int>> p) {

	int g;
	int n = p.size();

	vector<vector<int>> output(n, vector<int>(n));


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

		g = next_group++;

		vector<int> clique = { i };

		for (int y = i + 1; y < n; y++)
		{
			if (p[i][y] == 1) clique.emplace_back(y);
		}
		gnode[g] = i;

		for (int y : clique) {
			groups[y] = g;

			if (p[y] != p[gnode[g]]) goto impossible;
		}

		for (int i = 1; i < (int)clique.size(); i++)
		{
			output[clique[i]][clique[i - 1]] = output[clique[i - 1]][clique[i]] = 1;
		}

		siz[g] = clique.size();

		set <int> seen;
		for (int y = 0; y < i; y++)
		{
			if (p[i][y] != 0 && seen.count(groups[y]) == 0) {
				adj[g].push_back(groups[y]);
				seen.insert(groups[y]);
				adj[groups[y]].push_back(g);
			}
		}
	}

	// cerr << "Groups complete\n";

	// Combining groups
	// in each connected component, there must be either 2, 3, or none, but not both

	for (int i = 1; i < next_group; i++)
	{
		if (done[i]) continue;

		vector<int> gs = adj[i];
		gs.push_back(i);

		vector<int> twos, threes, ones;

		if (gs.size() == 1) continue;
		// cout << i << "\n";
		// for (int y : gs) cout << y << " ";
		// cout << "\n";

		for (int x : gs)
		{
			done[x] = true;
			int one = 0;
			bool two, three;
			two = three = false;

			for (int y : p[gnode[x]])
			{
				if (y == 1) one ++;
				else if (y == 2) two = true;
				else if (y == 3) three = true;
			}
			
			if (two && three) goto impossible;
			
			if (one > 1) ones.emplace_back(x); 
			else if (two) twos.emplace_back(x);
			else if (three) threes.emplace_back(x);
		}

		// cout << "Counting finished\n";

		// cerr << ones.size() << " " << twos.size() << " " << threes.size() << " \n";

		if (threes.empty())
		{
			// Twos

			if (gs.size() == 2) goto impossible;

			// Make a cycle
			for (int y = 0; y < (int)gs.size() - 1; y++)
			{
				output[gnode[gs[y]]][gnode[gs[y + 1]]] = output[gnode[gs[y + 1]]][gnode[gs[y]]] = 1;
			}
			output[gnode[gs[0]]][gnode[gs[gs.size() - 1]]] = output[gnode[gs[gs.size() - 1]]][gnode[gs[0]]] = 1;

			
		}
	}


	
	// Build
	build(output);
	return 1;


	impossible:

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 166 ms 24032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 166 ms 24032 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 169 ms 23968 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 75 ms 14092 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 38 ms 6272 KB Output is correct
21 Correct 152 ms 23960 KB Output is correct
22 Correct 161 ms 23952 KB Output is correct
23 Correct 166 ms 23964 KB Output is correct
24 Correct 166 ms 23956 KB Output is correct
25 Correct 67 ms 14104 KB Output is correct
26 Correct 63 ms 14108 KB Output is correct
27 Correct 155 ms 23952 KB Output is correct
28 Correct 159 ms 23960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 7 ms 1236 KB Output is correct
9 Correct 170 ms 24012 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 8 ms 1492 KB Output is correct
13 Correct 206 ms 28020 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Incorrect 0 ms 340 KB Answer gives possible 1 while actual possible 0
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 39 ms 6252 KB Output is correct
5 Correct 152 ms 24028 KB Output is correct
6 Correct 153 ms 23944 KB Output is correct
7 Correct 158 ms 23972 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 39 ms 6344 KB Output is correct
10 Correct 182 ms 24544 KB Output is correct
11 Correct 170 ms 23968 KB Output is correct
12 Correct 178 ms 27280 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 39 ms 6288 KB Output is correct
17 Correct 160 ms 24548 KB Output is correct
18 Correct 155 ms 24204 KB Output is correct
19 Correct 155 ms 24132 KB Output is correct
20 Correct 158 ms 24036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 166 ms 24032 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 169 ms 23968 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 75 ms 14092 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 38 ms 6272 KB Output is correct
21 Correct 152 ms 23960 KB Output is correct
22 Correct 161 ms 23952 KB Output is correct
23 Correct 166 ms 23964 KB Output is correct
24 Correct 166 ms 23956 KB Output is correct
25 Correct 67 ms 14104 KB Output is correct
26 Correct 63 ms 14108 KB Output is correct
27 Correct 155 ms 23952 KB Output is correct
28 Correct 159 ms 23960 KB Output is correct
29 Correct 1 ms 324 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 328 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 7 ms 1236 KB Output is correct
37 Correct 170 ms 24012 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 8 ms 1492 KB Output is correct
41 Correct 206 ms 28020 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Incorrect 0 ms 340 KB Answer gives possible 1 while actual possible 0
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 166 ms 24032 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 169 ms 23968 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 75 ms 14092 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 38 ms 6272 KB Output is correct
21 Correct 152 ms 23960 KB Output is correct
22 Correct 161 ms 23952 KB Output is correct
23 Correct 166 ms 23964 KB Output is correct
24 Correct 166 ms 23956 KB Output is correct
25 Correct 67 ms 14104 KB Output is correct
26 Correct 63 ms 14108 KB Output is correct
27 Correct 155 ms 23952 KB Output is correct
28 Correct 159 ms 23960 KB Output is correct
29 Correct 1 ms 324 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 328 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 7 ms 1236 KB Output is correct
37 Correct 170 ms 24012 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 8 ms 1492 KB Output is correct
41 Correct 206 ms 28020 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Incorrect 0 ms 340 KB Answer gives possible 1 while actual possible 0
44 Halted 0 ms 0 KB -