Submission #1115710

# Submission time Handle Problem Language Result Execution time Memory
1115710 2024-11-20T20:40:43 Z Pekiban Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
161 ms 28040 KB
#include "supertrees.h"
#include <bits/stdc++.h>

using namespace std;
#define pb push_back

const int N = 1001;
struct dsu {
	int p[N], sz[N];
	void init(int n) {
		fill(sz, sz+n, 1);
		iota(p, p+n, 0);
	}
	int get(int u) {
		if (u == p[u])	return u;
		return p[u] = get(p[u]);
	}
	bool unite(int u, int v) {
		u = get(u), v = get(v);
		if (u == v)	return 0;
		if (sz[u] < sz[v])	swap(u, v);
		sz[u] += sz[v];
		p[v] = u;
		return 1;
	}
} D;
bool vis[N];
int n;
vector<int> E;
vector<vector<int>> p;
void dfs(int s) {
	vis[s] = 1;
	E.pb(s);
	for (int i = 0; i < n; ++i) {
		if (p[s][D.get(i)] == 2 && !vis[D.get(i)])	dfs(D.get(i));
	}
}
int construct(vector<vector<int>> P) {
	p = P; n = p.size();
	D.init(n);
	vector<vector<int>> A(n, vector<int>(n, 0));
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (p[i][j] == 1) {
				if (D.unite(i, j))	A[i][j] = A[j][i] = 1;
			}
		}
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (p[i][j] == 3 || p[i][j] != p[D.get(i)][D.get(j)])	return 0;
		}
	}
	for (int u = 0; u < n; ++u) {
		if (!vis[D.get(u)])	{
			dfs(D.get(u));
			for (int i = 0; i < (int)E.size(); ++i) {
				for (int j = 0; j < i; ++j) {
					if (p[E[i]][E[j]] != 2)	return 0;
				}
			}
			if (E.size() == 1) {
				E.clear();
				continue;
			}
			if (E.size() == 2)	return 0;
			for (int i = 0; i+1 < (int)E.size(); ++i)	A[E[i]][E[i+1]] = A[E[i+1]][E[i]] = 1;
			A[E.back()][E[0]] = A[E[0]][E.back()] = 1;
			E.clear();
		}
	}
	build(A);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 6 ms 1360 KB Output is correct
7 Correct 135 ms 25928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 6 ms 1360 KB Output is correct
7 Correct 135 ms 25928 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 6 ms 1360 KB Output is correct
13 Correct 120 ms 26144 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 4 ms 848 KB Output is correct
17 Correct 70 ms 16200 KB Output is correct
18 Correct 1 ms 504 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 32 ms 6736 KB Output is correct
21 Correct 129 ms 25928 KB Output is correct
22 Correct 132 ms 25932 KB Output is correct
23 Correct 142 ms 25928 KB Output is correct
24 Correct 145 ms 26184 KB Output is correct
25 Correct 63 ms 16200 KB Output is correct
26 Correct 62 ms 16200 KB Output is correct
27 Correct 158 ms 26136 KB Output is correct
28 Correct 134 ms 26252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 440 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 7 ms 1360 KB Output is correct
9 Correct 137 ms 27980 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 6 ms 1360 KB Output is correct
13 Correct 150 ms 28040 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 4 ms 1104 KB Output is correct
17 Correct 77 ms 18248 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 44 ms 7372 KB Output is correct
22 Correct 131 ms 27984 KB Output is correct
23 Correct 161 ms 27976 KB Output is correct
24 Correct 143 ms 27976 KB Output is correct
25 Correct 57 ms 17992 KB Output is correct
26 Correct 59 ms 17992 KB Output is correct
27 Correct 123 ms 27928 KB Output is correct
28 Correct 140 ms 27976 KB Output is correct
29 Correct 57 ms 18064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 31 ms 6812 KB Output is correct
5 Correct 136 ms 25980 KB Output is correct
6 Correct 122 ms 25928 KB Output is correct
7 Correct 147 ms 25928 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 34 ms 6808 KB Output is correct
10 Correct 146 ms 25932 KB Output is correct
11 Correct 126 ms 26188 KB Output is correct
12 Correct 137 ms 26140 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 504 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 66 ms 6900 KB Output is correct
17 Correct 144 ms 26136 KB Output is correct
18 Correct 145 ms 25912 KB Output is correct
19 Correct 140 ms 26140 KB Output is correct
20 Correct 157 ms 26136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 6 ms 1360 KB Output is correct
7 Correct 135 ms 25928 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 6 ms 1360 KB Output is correct
13 Correct 120 ms 26144 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 4 ms 848 KB Output is correct
17 Correct 70 ms 16200 KB Output is correct
18 Correct 1 ms 504 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 32 ms 6736 KB Output is correct
21 Correct 129 ms 25928 KB Output is correct
22 Correct 132 ms 25932 KB Output is correct
23 Correct 142 ms 25928 KB Output is correct
24 Correct 145 ms 26184 KB Output is correct
25 Correct 63 ms 16200 KB Output is correct
26 Correct 62 ms 16200 KB Output is correct
27 Correct 158 ms 26136 KB Output is correct
28 Correct 134 ms 26252 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 440 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 7 ms 1360 KB Output is correct
37 Correct 137 ms 27980 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 6 ms 1360 KB Output is correct
41 Correct 150 ms 28040 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Correct 1 ms 336 KB Output is correct
44 Correct 4 ms 1104 KB Output is correct
45 Correct 77 ms 18248 KB Output is correct
46 Correct 1 ms 336 KB Output is correct
47 Correct 1 ms 336 KB Output is correct
48 Correct 1 ms 336 KB Output is correct
49 Correct 44 ms 7372 KB Output is correct
50 Correct 131 ms 27984 KB Output is correct
51 Correct 161 ms 27976 KB Output is correct
52 Correct 143 ms 27976 KB Output is correct
53 Correct 57 ms 17992 KB Output is correct
54 Correct 59 ms 17992 KB Output is correct
55 Correct 123 ms 27928 KB Output is correct
56 Correct 140 ms 27976 KB Output is correct
57 Correct 57 ms 18064 KB Output is correct
58 Correct 1 ms 336 KB Output is correct
59 Correct 1 ms 592 KB Output is correct
60 Correct 5 ms 1104 KB Output is correct
61 Correct 82 ms 18116 KB Output is correct
62 Correct 1 ms 336 KB Output is correct
63 Correct 1 ms 336 KB Output is correct
64 Correct 1 ms 336 KB Output is correct
65 Correct 36 ms 7264 KB Output is correct
66 Correct 70 ms 18064 KB Output is correct
67 Correct 71 ms 17992 KB Output is correct
68 Correct 68 ms 17992 KB Output is correct
69 Correct 68 ms 18068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 6 ms 1360 KB Output is correct
7 Correct 135 ms 25928 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 6 ms 1360 KB Output is correct
13 Correct 120 ms 26144 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 4 ms 848 KB Output is correct
17 Correct 70 ms 16200 KB Output is correct
18 Correct 1 ms 504 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 32 ms 6736 KB Output is correct
21 Correct 129 ms 25928 KB Output is correct
22 Correct 132 ms 25932 KB Output is correct
23 Correct 142 ms 25928 KB Output is correct
24 Correct 145 ms 26184 KB Output is correct
25 Correct 63 ms 16200 KB Output is correct
26 Correct 62 ms 16200 KB Output is correct
27 Correct 158 ms 26136 KB Output is correct
28 Correct 134 ms 26252 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 440 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 7 ms 1360 KB Output is correct
37 Correct 137 ms 27980 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 6 ms 1360 KB Output is correct
41 Correct 150 ms 28040 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Correct 1 ms 336 KB Output is correct
44 Correct 4 ms 1104 KB Output is correct
45 Correct 77 ms 18248 KB Output is correct
46 Correct 1 ms 336 KB Output is correct
47 Correct 1 ms 336 KB Output is correct
48 Correct 1 ms 336 KB Output is correct
49 Correct 44 ms 7372 KB Output is correct
50 Correct 131 ms 27984 KB Output is correct
51 Correct 161 ms 27976 KB Output is correct
52 Correct 143 ms 27976 KB Output is correct
53 Correct 57 ms 17992 KB Output is correct
54 Correct 59 ms 17992 KB Output is correct
55 Correct 123 ms 27928 KB Output is correct
56 Correct 140 ms 27976 KB Output is correct
57 Correct 57 ms 18064 KB Output is correct
58 Correct 1 ms 336 KB Output is correct
59 Correct 1 ms 336 KB Output is correct
60 Correct 1 ms 336 KB Output is correct
61 Correct 31 ms 6812 KB Output is correct
62 Correct 136 ms 25980 KB Output is correct
63 Correct 122 ms 25928 KB Output is correct
64 Correct 147 ms 25928 KB Output is correct
65 Correct 1 ms 336 KB Output is correct
66 Correct 34 ms 6808 KB Output is correct
67 Correct 146 ms 25932 KB Output is correct
68 Correct 126 ms 26188 KB Output is correct
69 Correct 137 ms 26140 KB Output is correct
70 Correct 1 ms 336 KB Output is correct
71 Correct 1 ms 504 KB Output is correct
72 Correct 1 ms 336 KB Output is correct
73 Correct 66 ms 6900 KB Output is correct
74 Correct 144 ms 26136 KB Output is correct
75 Correct 145 ms 25912 KB Output is correct
76 Correct 140 ms 26140 KB Output is correct
77 Correct 157 ms 26136 KB Output is correct
78 Correct 1 ms 336 KB Output is correct
79 Correct 1 ms 592 KB Output is correct
80 Correct 5 ms 1104 KB Output is correct
81 Correct 82 ms 18116 KB Output is correct
82 Correct 1 ms 336 KB Output is correct
83 Correct 1 ms 336 KB Output is correct
84 Correct 1 ms 336 KB Output is correct
85 Correct 36 ms 7264 KB Output is correct
86 Correct 70 ms 18064 KB Output is correct
87 Correct 71 ms 17992 KB Output is correct
88 Correct 68 ms 17992 KB Output is correct
89 Correct 68 ms 18068 KB Output is correct
90 Correct 1 ms 336 KB Output is correct
91 Correct 1 ms 336 KB Output is correct
92 Correct 4 ms 1104 KB Output is correct
93 Correct 71 ms 17992 KB Output is correct
94 Correct 1 ms 336 KB Output is correct
95 Correct 1 ms 508 KB Output is correct
96 Correct 1 ms 444 KB Output is correct
97 Correct 17 ms 4740 KB Output is correct
98 Correct 64 ms 18060 KB Output is correct
99 Correct 85 ms 18060 KB Output is correct
100 Correct 69 ms 18064 KB Output is correct
101 Correct 62 ms 18188 KB Output is correct
102 Correct 72 ms 18064 KB Output is correct
103 Correct 63 ms 18056 KB Output is correct
104 Correct 73 ms 18060 KB Output is correct
105 Correct 77 ms 18320 KB Output is correct