Submission #838050

# Submission time Handle Problem Language Result Execution time Memory
838050 2023-08-26T06:42:02 Z caganyanmaz Connecting Supertrees (IOI20_supertrees) C++17
96 / 100
171 ms 23900 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] == 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;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 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 0 ms 212 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 162 ms 21988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 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 0 ms 212 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 162 ms 21988 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 6 ms 1108 KB Output is correct
13 Correct 154 ms 21968 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 75 ms 12068 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 49 ms 5708 KB Output is correct
21 Correct 150 ms 22012 KB Output is correct
22 Correct 152 ms 22024 KB Output is correct
23 Correct 157 ms 22068 KB Output is correct
24 Correct 151 ms 22020 KB Output is correct
25 Correct 62 ms 12080 KB Output is correct
26 Correct 60 ms 12112 KB Output is correct
27 Correct 155 ms 21964 KB Output is correct
28 Correct 155 ms 21964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 7 ms 1136 KB Output is correct
9 Correct 150 ms 22052 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 6 ms 1108 KB Output is correct
13 Correct 151 ms 22076 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 66 ms 12108 KB Output is correct
18 Correct 1 ms 256 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 5708 KB Output is correct
22 Correct 151 ms 21964 KB Output is correct
23 Correct 153 ms 21964 KB Output is correct
24 Correct 171 ms 22024 KB Output is correct
25 Correct 60 ms 12108 KB Output is correct
26 Correct 61 ms 12080 KB Output is correct
27 Correct 149 ms 22056 KB Output is correct
28 Correct 156 ms 22060 KB Output is correct
29 Correct 60 ms 12108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 39 ms 6220 KB Output is correct
5 Correct 149 ms 23756 KB Output is correct
6 Correct 150 ms 23776 KB Output is correct
7 Correct 157 ms 23756 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 40 ms 6180 KB Output is correct
10 Correct 150 ms 23756 KB Output is correct
11 Correct 154 ms 23812 KB Output is correct
12 Correct 156 ms 23852 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 38 ms 6228 KB Output is correct
17 Correct 151 ms 23748 KB Output is correct
18 Correct 153 ms 23872 KB Output is correct
19 Correct 156 ms 23900 KB Output is correct
20 Correct 152 ms 23788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 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 0 ms 212 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 162 ms 21988 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 6 ms 1108 KB Output is correct
13 Correct 154 ms 21968 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 75 ms 12068 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 49 ms 5708 KB Output is correct
21 Correct 150 ms 22012 KB Output is correct
22 Correct 152 ms 22024 KB Output is correct
23 Correct 157 ms 22068 KB Output is correct
24 Correct 151 ms 22020 KB Output is correct
25 Correct 62 ms 12080 KB Output is correct
26 Correct 60 ms 12112 KB Output is correct
27 Correct 155 ms 21964 KB Output is correct
28 Correct 155 ms 21964 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 7 ms 1136 KB Output is correct
37 Correct 150 ms 22052 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 6 ms 1108 KB Output is correct
41 Correct 151 ms 22076 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 3 ms 724 KB Output is correct
45 Correct 66 ms 12108 KB Output is correct
46 Correct 1 ms 256 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 5708 KB Output is correct
50 Correct 151 ms 21964 KB Output is correct
51 Correct 153 ms 21964 KB Output is correct
52 Correct 171 ms 22024 KB Output is correct
53 Correct 60 ms 12108 KB Output is correct
54 Correct 61 ms 12080 KB Output is correct
55 Correct 149 ms 22056 KB Output is correct
56 Correct 156 ms 22060 KB Output is correct
57 Correct 60 ms 12108 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 0 ms 340 KB Output is correct
60 Correct 3 ms 852 KB Output is correct
61 Correct 67 ms 14104 KB Output is correct
62 Correct 1 ms 212 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 38 ms 6272 KB Output is correct
66 Correct 62 ms 14100 KB Output is correct
67 Correct 62 ms 14104 KB Output is correct
68 Correct 60 ms 14028 KB Output is correct
69 Correct 63 ms 14024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 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 0 ms 212 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 162 ms 21988 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 6 ms 1108 KB Output is correct
13 Correct 154 ms 21968 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 75 ms 12068 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 49 ms 5708 KB Output is correct
21 Correct 150 ms 22012 KB Output is correct
22 Correct 152 ms 22024 KB Output is correct
23 Correct 157 ms 22068 KB Output is correct
24 Correct 151 ms 22020 KB Output is correct
25 Correct 62 ms 12080 KB Output is correct
26 Correct 60 ms 12112 KB Output is correct
27 Correct 155 ms 21964 KB Output is correct
28 Correct 155 ms 21964 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 7 ms 1136 KB Output is correct
37 Correct 150 ms 22052 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 6 ms 1108 KB Output is correct
41 Correct 151 ms 22076 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 3 ms 724 KB Output is correct
45 Correct 66 ms 12108 KB Output is correct
46 Correct 1 ms 256 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 5708 KB Output is correct
50 Correct 151 ms 21964 KB Output is correct
51 Correct 153 ms 21964 KB Output is correct
52 Correct 171 ms 22024 KB Output is correct
53 Correct 60 ms 12108 KB Output is correct
54 Correct 61 ms 12080 KB Output is correct
55 Correct 149 ms 22056 KB Output is correct
56 Correct 156 ms 22060 KB Output is correct
57 Correct 60 ms 12108 KB Output is correct
58 Correct 0 ms 336 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 39 ms 6220 KB Output is correct
62 Correct 149 ms 23756 KB Output is correct
63 Correct 150 ms 23776 KB Output is correct
64 Correct 157 ms 23756 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 40 ms 6180 KB Output is correct
67 Correct 150 ms 23756 KB Output is correct
68 Correct 154 ms 23812 KB Output is correct
69 Correct 156 ms 23852 KB Output is correct
70 Correct 1 ms 512 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 1 ms 212 KB Output is correct
73 Correct 38 ms 6228 KB Output is correct
74 Correct 151 ms 23748 KB Output is correct
75 Correct 153 ms 23872 KB Output is correct
76 Correct 156 ms 23900 KB Output is correct
77 Correct 152 ms 23788 KB Output is correct
78 Correct 0 ms 340 KB Output is correct
79 Correct 0 ms 340 KB Output is correct
80 Correct 3 ms 852 KB Output is correct
81 Correct 67 ms 14104 KB Output is correct
82 Correct 1 ms 212 KB Output is correct
83 Correct 1 ms 212 KB Output is correct
84 Correct 0 ms 212 KB Output is correct
85 Correct 38 ms 6272 KB Output is correct
86 Correct 62 ms 14100 KB Output is correct
87 Correct 62 ms 14104 KB Output is correct
88 Correct 60 ms 14028 KB Output is correct
89 Correct 63 ms 14024 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 1 ms 212 KB Output is correct
92 Correct 3 ms 828 KB Output is correct
93 Correct 65 ms 14112 KB Output is correct
94 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
95 Halted 0 ms 0 KB -