답안 #779135

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
779135 2023-07-11T08:15:34 Z Josia 슈퍼트리 잇기 (IOI20_supertrees) C++17
21 / 100
166 ms 24044 KB
#include "supertrees.h"
#include <vector>
#include <bits/stdc++.h>

using namespace std;




struct uf {
	vector<int> chefs;
	uf (int n) {
		chefs.resize(n);
		for (int i = 0; i<n; i++) chefs[i] = i;
	}

	int find(int x) {
		if (chefs[x] == x) return x;
		return chefs[x] = find(chefs[x]);
	}

	void unite(int a, int b) {
		a = find(a);
		b = find(b);

		chefs[a] = b;
	}
};




int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	if (n == 1) {
		if (p[0][0] == 1) {
			build({{0}});
			return 1;
		}
		return 0;
	}
	vector<vector<int>> answer(n, vector<int>(n));


	uf u(n);

	for (int i = 0; i<n; i++) {
		for (int j = 0; j<n; j++) {
			if (p[i][j]) u.unite(i, j);
		}
	}

	for (int i = 0; i<n; i++) {
		for (int j = 0; j<n; j++) {
			if (p[i][j] != (u.find(i) == u.find(j))) return 0;
		}
	}

	vector<vector<int>> vals(n);

	for (int i = 0; i<n; i++) {
		for (int j = 0; j<n; j++) {
			if (u.find(j) == i) vals[i].push_back(j);
		}
	}

	for (auto v: vals) {

		for (int i = 0; i<(int)(v.size())-1; i++) {
			answer[v[i]][v[i+1]] = 1;
			answer[v[i+1]][v[i]] = 1;
		}

	}

	build(answer);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 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 158 ms 22020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 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 158 ms 22020 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 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 147 ms 22004 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 68 ms 12604 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 38 ms 6200 KB Output is correct
21 Correct 166 ms 23936 KB Output is correct
22 Correct 150 ms 23924 KB Output is correct
23 Correct 158 ms 23936 KB Output is correct
24 Correct 159 ms 23988 KB Output is correct
25 Correct 58 ms 14080 KB Output is correct
26 Correct 57 ms 14068 KB Output is correct
27 Correct 156 ms 24036 KB Output is correct
28 Correct 161 ms 24044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB Answer gives possible 0 while actual possible 1
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Answer gives possible 0 while actual possible 1
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 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 158 ms 22020 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 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 147 ms 22004 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 68 ms 12604 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 38 ms 6200 KB Output is correct
21 Correct 166 ms 23936 KB Output is correct
22 Correct 150 ms 23924 KB Output is correct
23 Correct 158 ms 23936 KB Output is correct
24 Correct 159 ms 23988 KB Output is correct
25 Correct 58 ms 14080 KB Output is correct
26 Correct 57 ms 14068 KB Output is correct
27 Correct 156 ms 24036 KB Output is correct
28 Correct 161 ms 24044 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Incorrect 1 ms 212 KB Answer gives possible 0 while actual possible 1
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 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 158 ms 22020 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 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 147 ms 22004 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 68 ms 12604 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 38 ms 6200 KB Output is correct
21 Correct 166 ms 23936 KB Output is correct
22 Correct 150 ms 23924 KB Output is correct
23 Correct 158 ms 23936 KB Output is correct
24 Correct 159 ms 23988 KB Output is correct
25 Correct 58 ms 14080 KB Output is correct
26 Correct 57 ms 14068 KB Output is correct
27 Correct 156 ms 24036 KB Output is correct
28 Correct 161 ms 24044 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Incorrect 1 ms 212 KB Answer gives possible 0 while actual possible 1
34 Halted 0 ms 0 KB -