Submission #1115708

# Submission time Handle Problem Language Result Execution time Memory
1115708 2024-11-20T20:38:14 Z Pekiban Connecting Supertrees (IOI20_supertrees) C++17
56 / 100
146 ms 26148 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;
			}
			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 504 KB Output is correct
2 Correct 1 ms 532 KB Output is correct
3 Correct 1 ms 520 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 6 ms 1360 KB Output is correct
7 Correct 128 ms 25932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 1 ms 532 KB Output is correct
3 Correct 1 ms 520 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 6 ms 1360 KB Output is correct
7 Correct 128 ms 25932 KB Output is correct
8 Correct 1 ms 504 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 123 ms 26148 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 5 ms 848 KB Output is correct
17 Correct 78 ms 16200 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 35 ms 6736 KB Output is correct
21 Correct 134 ms 25936 KB Output is correct
22 Correct 136 ms 25928 KB Output is correct
23 Correct 146 ms 25936 KB Output is correct
24 Correct 135 ms 25928 KB Output is correct
25 Correct 57 ms 16156 KB Output is correct
26 Correct 57 ms 16156 KB Output is correct
27 Correct 141 ms 26136 KB Output is correct
28 Correct 135 ms 25928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Incorrect 1 ms 336 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 32 ms 6736 KB Output is correct
5 Correct 130 ms 25928 KB Output is correct
6 Correct 136 ms 25928 KB Output is correct
7 Correct 137 ms 26144 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 31 ms 6728 KB Output is correct
10 Correct 130 ms 25928 KB Output is correct
11 Correct 131 ms 25928 KB Output is correct
12 Correct 144 ms 26144 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 32 ms 6736 KB Output is correct
17 Correct 133 ms 25928 KB Output is correct
18 Correct 135 ms 26140 KB Output is correct
19 Correct 133 ms 25928 KB Output is correct
20 Correct 141 ms 26148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 1 ms 532 KB Output is correct
3 Correct 1 ms 520 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 6 ms 1360 KB Output is correct
7 Correct 128 ms 25932 KB Output is correct
8 Correct 1 ms 504 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 123 ms 26148 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 5 ms 848 KB Output is correct
17 Correct 78 ms 16200 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 35 ms 6736 KB Output is correct
21 Correct 134 ms 25936 KB Output is correct
22 Correct 136 ms 25928 KB Output is correct
23 Correct 146 ms 25936 KB Output is correct
24 Correct 135 ms 25928 KB Output is correct
25 Correct 57 ms 16156 KB Output is correct
26 Correct 57 ms 16156 KB Output is correct
27 Correct 141 ms 26136 KB Output is correct
28 Correct 135 ms 25928 KB Output is correct
29 Correct 1 ms 504 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Incorrect 1 ms 336 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 1 ms 532 KB Output is correct
3 Correct 1 ms 520 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 6 ms 1360 KB Output is correct
7 Correct 128 ms 25932 KB Output is correct
8 Correct 1 ms 504 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 123 ms 26148 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 5 ms 848 KB Output is correct
17 Correct 78 ms 16200 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 35 ms 6736 KB Output is correct
21 Correct 134 ms 25936 KB Output is correct
22 Correct 136 ms 25928 KB Output is correct
23 Correct 146 ms 25936 KB Output is correct
24 Correct 135 ms 25928 KB Output is correct
25 Correct 57 ms 16156 KB Output is correct
26 Correct 57 ms 16156 KB Output is correct
27 Correct 141 ms 26136 KB Output is correct
28 Correct 135 ms 25928 KB Output is correct
29 Correct 1 ms 504 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Incorrect 1 ms 336 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -