답안 #838261

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
838261 2023-08-26T12:18:00 Z caganyanmaz 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
183 ms 24096 KB
#include <bits/stdc++.h>
#include "supertrees.h"
//#define DEBUGGING
#ifdef DEBUGGING
#include "../debug.h"
#else
#define debug(x...) void(42)
#endif
using namespace std;
constexpr static int MXN = 1e3 + 5;
struct Node
{
	int head, tail, size, nxt;
	Node(int i) : head(i), tail(i), size(1), nxt(-1) {}
	Node() : Node(-1) {}
};
Node node[MXN];
Node supernode[MXN];

void merge(int a, int b, Node arr[MXN]);
int construct(vector<vector<int>> p)
{
	int n = p.size();
	vector<vector<int>> answer(n, vector<int>(n));
	for (int i = 0; i < n; i++) 
		node[i] = Node(i);
	for (int i = 0; i < n; i++)
		for (int j = i+1; j < n; j++)
			if (p[i][j] == 3)
				return 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = i+1; j < n; j++)
		{
			if (p[i][j] == 1 && node[i].head != node[j].head)
			{
				merge(node[i].head, node[j].head, node);
				answer[i][j] = answer[j][i] = 1;
			}
		}
	}
	for (int i = 0; i < n; i++)
		supernode[i] = Node(i);
	for (int i = 0; i < n; i++)
		for (int j = i+1; j < n; j++)
			if (p[i][j] == 2 && supernode[node[i].head].head != supernode[node[j].head].head)
				merge(supernode[node[i].head].head, supernode[node[j].head].head, supernode);
	for (int i = 0; i < n; i++)
		for (int j = i+1; j < n; j++)
			if ((p[i][j] == 0 && supernode[node[i].head].head == supernode[node[j].head].head) || (p[i][j] == 1 && node[i].head != node[j].head) || (p[i][j] == 2 && (node[i].head == node[j].head || supernode[node[i].head].head != supernode[node[j].head].head)))
				return 0;
	for (int i = 0; i < n; i++)
	{
		if (i != node[i].head || i != supernode[i].head || supernode[i].size == 1)
			continue;
		if (supernode[i].size == 2)
			return 0;
		for (int j = i; supernode[j].nxt != -1; j = supernode[j].nxt)
			answer[j][supernode[j].nxt] = answer[supernode[j].nxt][j] = 1;
		answer[i][supernode[i].tail] = answer[supernode[i].tail][i] = 1;
	}
	build(answer);
	return 1;
}
void merge(int a, int b, Node arr[MXN])
{
	if (arr[a].size < arr[b].size) swap(a, b);
	arr[a].size += arr[b].size;
	arr[arr[a].tail].nxt = b;
	arr[a].tail = arr[b].tail;
	for (;b!=-1;b=arr[b].nxt)
		arr[b].head = a;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 508 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 165 ms 23924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 508 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 165 ms 23924 KB Output is correct
8 Correct 1 ms 360 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1360 KB Output is correct
13 Correct 155 ms 22528 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 71 ms 12620 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 38 ms 6228 KB Output is correct
21 Correct 158 ms 22600 KB Output is correct
22 Correct 164 ms 22696 KB Output is correct
23 Correct 176 ms 22516 KB Output is correct
24 Correct 157 ms 22468 KB Output is correct
25 Correct 66 ms 12716 KB Output is correct
26 Correct 70 ms 12640 KB Output is correct
27 Correct 164 ms 22528 KB Output is correct
28 Correct 164 ms 22624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 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 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 7 ms 1236 KB Output is correct
9 Correct 173 ms 22516 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 156 ms 22544 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 71 ms 12576 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 38 ms 6228 KB Output is correct
22 Correct 160 ms 22480 KB Output is correct
23 Correct 158 ms 22532 KB Output is correct
24 Correct 169 ms 22664 KB Output is correct
25 Correct 71 ms 12576 KB Output is correct
26 Correct 68 ms 12688 KB Output is correct
27 Correct 155 ms 22476 KB Output is correct
28 Correct 183 ms 22496 KB Output is correct
29 Correct 70 ms 12604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 39 ms 6228 KB Output is correct
5 Correct 155 ms 23944 KB Output is correct
6 Correct 159 ms 23956 KB Output is correct
7 Correct 163 ms 23936 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 39 ms 6220 KB Output is correct
10 Correct 171 ms 24080 KB Output is correct
11 Correct 153 ms 24012 KB Output is correct
12 Correct 160 ms 23956 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 39 ms 6220 KB Output is correct
17 Correct 153 ms 24028 KB Output is correct
18 Correct 154 ms 24096 KB Output is correct
19 Correct 153 ms 23952 KB Output is correct
20 Correct 155 ms 24012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 508 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 165 ms 23924 KB Output is correct
8 Correct 1 ms 360 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1360 KB Output is correct
13 Correct 155 ms 22528 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 71 ms 12620 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 38 ms 6228 KB Output is correct
21 Correct 158 ms 22600 KB Output is correct
22 Correct 164 ms 22696 KB Output is correct
23 Correct 176 ms 22516 KB Output is correct
24 Correct 157 ms 22468 KB Output is correct
25 Correct 66 ms 12716 KB Output is correct
26 Correct 70 ms 12640 KB Output is correct
27 Correct 164 ms 22528 KB Output is correct
28 Correct 164 ms 22624 KB Output is correct
29 Correct 1 ms 212 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 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 7 ms 1236 KB Output is correct
37 Correct 173 ms 22516 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 7 ms 1236 KB Output is correct
41 Correct 156 ms 22544 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 3 ms 852 KB Output is correct
45 Correct 71 ms 12576 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 38 ms 6228 KB Output is correct
50 Correct 160 ms 22480 KB Output is correct
51 Correct 158 ms 22532 KB Output is correct
52 Correct 169 ms 22664 KB Output is correct
53 Correct 71 ms 12576 KB Output is correct
54 Correct 68 ms 12688 KB Output is correct
55 Correct 155 ms 22476 KB Output is correct
56 Correct 183 ms 22496 KB Output is correct
57 Correct 70 ms 12604 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 3 ms 852 KB Output is correct
61 Correct 69 ms 14096 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 39 ms 6220 KB Output is correct
66 Correct 65 ms 14100 KB Output is correct
67 Correct 65 ms 14024 KB Output is correct
68 Correct 66 ms 14100 KB Output is correct
69 Correct 65 ms 14028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 508 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 165 ms 23924 KB Output is correct
8 Correct 1 ms 360 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1360 KB Output is correct
13 Correct 155 ms 22528 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 71 ms 12620 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 38 ms 6228 KB Output is correct
21 Correct 158 ms 22600 KB Output is correct
22 Correct 164 ms 22696 KB Output is correct
23 Correct 176 ms 22516 KB Output is correct
24 Correct 157 ms 22468 KB Output is correct
25 Correct 66 ms 12716 KB Output is correct
26 Correct 70 ms 12640 KB Output is correct
27 Correct 164 ms 22528 KB Output is correct
28 Correct 164 ms 22624 KB Output is correct
29 Correct 1 ms 212 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 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 7 ms 1236 KB Output is correct
37 Correct 173 ms 22516 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 7 ms 1236 KB Output is correct
41 Correct 156 ms 22544 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 3 ms 852 KB Output is correct
45 Correct 71 ms 12576 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 38 ms 6228 KB Output is correct
50 Correct 160 ms 22480 KB Output is correct
51 Correct 158 ms 22532 KB Output is correct
52 Correct 169 ms 22664 KB Output is correct
53 Correct 71 ms 12576 KB Output is correct
54 Correct 68 ms 12688 KB Output is correct
55 Correct 155 ms 22476 KB Output is correct
56 Correct 183 ms 22496 KB Output is correct
57 Correct 70 ms 12604 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 39 ms 6228 KB Output is correct
62 Correct 155 ms 23944 KB Output is correct
63 Correct 159 ms 23956 KB Output is correct
64 Correct 163 ms 23936 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 39 ms 6220 KB Output is correct
67 Correct 171 ms 24080 KB Output is correct
68 Correct 153 ms 24012 KB Output is correct
69 Correct 160 ms 23956 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 1 ms 212 KB Output is correct
73 Correct 39 ms 6220 KB Output is correct
74 Correct 153 ms 24028 KB Output is correct
75 Correct 154 ms 24096 KB Output is correct
76 Correct 153 ms 23952 KB Output is correct
77 Correct 155 ms 24012 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 1 ms 212 KB Output is correct
80 Correct 3 ms 852 KB Output is correct
81 Correct 69 ms 14096 KB Output is correct
82 Correct 0 ms 212 KB Output is correct
83 Correct 1 ms 212 KB Output is correct
84 Correct 1 ms 212 KB Output is correct
85 Correct 39 ms 6220 KB Output is correct
86 Correct 65 ms 14100 KB Output is correct
87 Correct 65 ms 14024 KB Output is correct
88 Correct 66 ms 14100 KB Output is correct
89 Correct 65 ms 14028 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 0 ms 212 KB Output is correct
92 Correct 3 ms 852 KB Output is correct
93 Correct 62 ms 14028 KB Output is correct
94 Correct 0 ms 212 KB Output is correct
95 Correct 1 ms 340 KB Output is correct
96 Correct 1 ms 212 KB Output is correct
97 Correct 16 ms 3796 KB Output is correct
98 Correct 62 ms 14032 KB Output is correct
99 Correct 64 ms 14108 KB Output is correct
100 Correct 61 ms 14100 KB Output is correct
101 Correct 62 ms 14028 KB Output is correct
102 Correct 60 ms 14028 KB Output is correct
103 Correct 61 ms 14028 KB Output is correct
104 Correct 60 ms 14116 KB Output is correct
105 Correct 66 ms 14024 KB Output is correct