답안 #1115703

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1115703 2024-11-20T20:22:40 Z Pekiban 슈퍼트리 잇기 (IOI20_supertrees) C++17
21 / 100
144 ms 28048 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 i = 0; i < n; ++i) {
		if (!vis[D.get(i)])	{
			dfs(D.get(i));
			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;
		}
	}
	build(A);
	return 1;
}
# 결과 실행 시간 메모리 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 7 ms 1360 KB Output is correct
7 Correct 129 ms 27976 KB Output is correct
# 결과 실행 시간 메모리 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 7 ms 1360 KB Output is correct
7 Correct 129 ms 27976 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 134 ms 27976 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 504 KB Output is correct
16 Correct 4 ms 1104 KB Output is correct
17 Correct 77 ms 18064 KB Output is correct
18 Correct 1 ms 500 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 35 ms 7200 KB Output is correct
21 Correct 134 ms 27976 KB Output is correct
22 Correct 134 ms 27916 KB Output is correct
23 Correct 139 ms 27976 KB Output is correct
24 Correct 126 ms 27976 KB Output is correct
25 Correct 58 ms 17996 KB Output is correct
26 Correct 55 ms 18192 KB Output is correct
27 Correct 131 ms 27976 KB Output is correct
28 Correct 126 ms 28048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 440 KB Output is correct
4 Incorrect 1 ms 336 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 38 ms 7256 KB Output is correct
5 Correct 135 ms 27976 KB Output is correct
6 Correct 129 ms 27976 KB Output is correct
7 Correct 144 ms 27976 KB Output is correct
8 Incorrect 1 ms 336 KB Answer gives possible 0 while actual possible 1
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 7 ms 1360 KB Output is correct
7 Correct 129 ms 27976 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 134 ms 27976 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 504 KB Output is correct
16 Correct 4 ms 1104 KB Output is correct
17 Correct 77 ms 18064 KB Output is correct
18 Correct 1 ms 500 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 35 ms 7200 KB Output is correct
21 Correct 134 ms 27976 KB Output is correct
22 Correct 134 ms 27916 KB Output is correct
23 Correct 139 ms 27976 KB Output is correct
24 Correct 126 ms 27976 KB Output is correct
25 Correct 58 ms 17996 KB Output is correct
26 Correct 55 ms 18192 KB Output is correct
27 Correct 131 ms 27976 KB Output is correct
28 Correct 126 ms 28048 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 440 KB Output is correct
32 Incorrect 1 ms 336 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 7 ms 1360 KB Output is correct
7 Correct 129 ms 27976 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 134 ms 27976 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 504 KB Output is correct
16 Correct 4 ms 1104 KB Output is correct
17 Correct 77 ms 18064 KB Output is correct
18 Correct 1 ms 500 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 35 ms 7200 KB Output is correct
21 Correct 134 ms 27976 KB Output is correct
22 Correct 134 ms 27916 KB Output is correct
23 Correct 139 ms 27976 KB Output is correct
24 Correct 126 ms 27976 KB Output is correct
25 Correct 58 ms 17996 KB Output is correct
26 Correct 55 ms 18192 KB Output is correct
27 Correct 131 ms 27976 KB Output is correct
28 Correct 126 ms 28048 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 440 KB Output is correct
32 Incorrect 1 ms 336 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -