Submission #1039659

# Submission time Handle Problem Language Result Execution time Memory
1039659 2024-07-31T07:04:02 Z DorostWef Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
137 ms 32336 KB
#include "supertrees.h"
#include <bits/stdc++.h>

using namespace std;
const int N = 1032;
vector <int> g1[N], g2[N];
int r1[N], r2[N];
bool vis[N];
vector <int> v[N];

void dfs1 (int v) {
	vis[v] = true;
	for (int u : g1[v]) {
		if (!vis[u]) {
			r1[u] = r1[v];
			dfs1 (u);
		}
	}
}

void dfs2 (int v) {
	vis[v] = true;
	for (int u : g2[v]) {
		if (!vis[u]) {
			r2[u] = r2[v];
			dfs2 (u);
		}
	}
}

int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	std::vector<std::vector<int>> ans;
	for (int i = 0; i < n; i++) {
		std::vector<int> row;
		row.resize(n);
		ans.push_back(row);
	}
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (p[i][j] == 1) {
				g1[i].push_back(j);
				g1[j].push_back(i);
			} 
			if (p[i][j] >= 1) {
				g2[i].push_back(j);
				g2[j].push_back(i);
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (!vis[i]) {
			r1[i] = i;
			dfs1(i);
		}
	}
	for (int i = 0; i < n; i++) 
		vis[i] = false;
	for (int i = 0; i < n; i++) {
		if (!vis[i]) {
			r2[i] = i;
			dfs2(i);
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			int w;
			if (r2[i] != r2[j]) {
				w = 0;
			} else if (r1[i] == r1[j]) {
				w = 1;
			} else {
				w = 2;
			}
			if (p[i][j] != w)
				return 0;
		}
	}
	for (int i = 0; i < n; i++) {
		if (r1[i] != i) {
			ans[i][r1[i]] = 1;
			ans[r1[i]][i] = 1;
		} else {
			v[r2[i]].push_back(i);
		}
	}
	for (int i = 0; i < n; i++) {
		if (v[i].size() == 2)
			return 0;
		if (v[i].size() <= 1)
			continue;
		int sz = (int)v[i].size();
		for (int j = 0; j < sz; j++) {
			ans[v[i][j]][v[i][(j + 1) % sz]] = true;
			ans[v[i][(j + 1) % sz]][v[i][j]] = true;
		}
	}
	build(ans);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1900 KB Output is correct
7 Correct 122 ms 32336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1900 KB Output is correct
7 Correct 122 ms 32336 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1368 KB Output is correct
13 Correct 112 ms 24144 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 1296 KB Output is correct
17 Correct 64 ms 19672 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 30 ms 6492 KB Output is correct
21 Correct 129 ms 25292 KB Output is correct
22 Correct 113 ms 24164 KB Output is correct
23 Correct 131 ms 28244 KB Output is correct
24 Correct 112 ms 24068 KB Output is correct
25 Correct 53 ms 15192 KB Output is correct
26 Correct 50 ms 14292 KB Output is correct
27 Correct 126 ms 30300 KB Output is correct
28 Correct 121 ms 24148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 5 ms 1468 KB Output is correct
9 Correct 117 ms 24140 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1624 KB Output is correct
13 Correct 137 ms 28244 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 62 ms 16976 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 29 ms 6348 KB Output is correct
22 Correct 119 ms 24776 KB Output is correct
23 Correct 121 ms 24152 KB Output is correct
24 Correct 130 ms 27352 KB Output is correct
25 Correct 63 ms 14160 KB Output is correct
26 Correct 54 ms 14676 KB Output is correct
27 Correct 113 ms 24120 KB Output is correct
28 Correct 121 ms 26196 KB Output is correct
29 Correct 51 ms 14156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 29 ms 6484 KB Output is correct
5 Correct 117 ms 25088 KB Output is correct
6 Correct 112 ms 24148 KB Output is correct
7 Correct 127 ms 28240 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 28 ms 6356 KB Output is correct
10 Correct 114 ms 24784 KB Output is correct
11 Correct 113 ms 24148 KB Output is correct
12 Correct 122 ms 27340 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 31 ms 6492 KB Output is correct
17 Correct 123 ms 24652 KB Output is correct
18 Correct 123 ms 24772 KB Output is correct
19 Correct 117 ms 24400 KB Output is correct
20 Correct 112 ms 24148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1900 KB Output is correct
7 Correct 122 ms 32336 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1368 KB Output is correct
13 Correct 112 ms 24144 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 1296 KB Output is correct
17 Correct 64 ms 19672 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 30 ms 6492 KB Output is correct
21 Correct 129 ms 25292 KB Output is correct
22 Correct 113 ms 24164 KB Output is correct
23 Correct 131 ms 28244 KB Output is correct
24 Correct 112 ms 24068 KB Output is correct
25 Correct 53 ms 15192 KB Output is correct
26 Correct 50 ms 14292 KB Output is correct
27 Correct 126 ms 30300 KB Output is correct
28 Correct 121 ms 24148 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 5 ms 1468 KB Output is correct
37 Correct 117 ms 24140 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 5 ms 1624 KB Output is correct
41 Correct 137 ms 28244 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 1116 KB Output is correct
45 Correct 62 ms 16976 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 344 KB Output is correct
49 Correct 29 ms 6348 KB Output is correct
50 Correct 119 ms 24776 KB Output is correct
51 Correct 121 ms 24152 KB Output is correct
52 Correct 130 ms 27352 KB Output is correct
53 Correct 63 ms 14160 KB Output is correct
54 Correct 54 ms 14676 KB Output is correct
55 Correct 113 ms 24120 KB Output is correct
56 Correct 121 ms 26196 KB Output is correct
57 Correct 51 ms 14156 KB Output is correct
58 Correct 0 ms 344 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 3 ms 1264 KB Output is correct
61 Correct 65 ms 20696 KB Output is correct
62 Correct 0 ms 344 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 29 ms 6352 KB Output is correct
66 Correct 58 ms 14928 KB Output is correct
67 Correct 58 ms 14672 KB Output is correct
68 Correct 51 ms 14416 KB Output is correct
69 Correct 50 ms 14164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1900 KB Output is correct
7 Correct 122 ms 32336 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1368 KB Output is correct
13 Correct 112 ms 24144 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 1296 KB Output is correct
17 Correct 64 ms 19672 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 30 ms 6492 KB Output is correct
21 Correct 129 ms 25292 KB Output is correct
22 Correct 113 ms 24164 KB Output is correct
23 Correct 131 ms 28244 KB Output is correct
24 Correct 112 ms 24068 KB Output is correct
25 Correct 53 ms 15192 KB Output is correct
26 Correct 50 ms 14292 KB Output is correct
27 Correct 126 ms 30300 KB Output is correct
28 Correct 121 ms 24148 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 5 ms 1468 KB Output is correct
37 Correct 117 ms 24140 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 5 ms 1624 KB Output is correct
41 Correct 137 ms 28244 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 1116 KB Output is correct
45 Correct 62 ms 16976 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 344 KB Output is correct
49 Correct 29 ms 6348 KB Output is correct
50 Correct 119 ms 24776 KB Output is correct
51 Correct 121 ms 24152 KB Output is correct
52 Correct 130 ms 27352 KB Output is correct
53 Correct 63 ms 14160 KB Output is correct
54 Correct 54 ms 14676 KB Output is correct
55 Correct 113 ms 24120 KB Output is correct
56 Correct 121 ms 26196 KB Output is correct
57 Correct 51 ms 14156 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 344 KB Output is correct
61 Correct 29 ms 6484 KB Output is correct
62 Correct 117 ms 25088 KB Output is correct
63 Correct 112 ms 24148 KB Output is correct
64 Correct 127 ms 28240 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 28 ms 6356 KB Output is correct
67 Correct 114 ms 24784 KB Output is correct
68 Correct 113 ms 24148 KB Output is correct
69 Correct 122 ms 27340 KB Output is correct
70 Correct 1 ms 348 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 31 ms 6492 KB Output is correct
74 Correct 123 ms 24652 KB Output is correct
75 Correct 123 ms 24772 KB Output is correct
76 Correct 117 ms 24400 KB Output is correct
77 Correct 112 ms 24148 KB Output is correct
78 Correct 0 ms 344 KB Output is correct
79 Correct 0 ms 348 KB Output is correct
80 Correct 3 ms 1264 KB Output is correct
81 Correct 65 ms 20696 KB Output is correct
82 Correct 0 ms 344 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 29 ms 6352 KB Output is correct
86 Correct 58 ms 14928 KB Output is correct
87 Correct 58 ms 14672 KB Output is correct
88 Correct 51 ms 14416 KB Output is correct
89 Correct 50 ms 14164 KB Output is correct
90 Correct 0 ms 348 KB Output is correct
91 Correct 0 ms 348 KB Output is correct
92 Correct 3 ms 1372 KB Output is correct
93 Correct 62 ms 20140 KB Output is correct
94 Correct 1 ms 344 KB Output is correct
95 Correct 1 ms 344 KB Output is correct
96 Correct 0 ms 344 KB Output is correct
97 Correct 13 ms 3932 KB Output is correct
98 Correct 51 ms 14672 KB Output is correct
99 Correct 52 ms 14672 KB Output is correct
100 Correct 57 ms 14536 KB Output is correct
101 Correct 49 ms 14160 KB Output is correct
102 Correct 59 ms 18260 KB Output is correct
103 Correct 73 ms 18260 KB Output is correct
104 Correct 60 ms 21192 KB Output is correct
105 Correct 63 ms 17228 KB Output is correct