답안 #365014

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
365014 2021-02-10T18:16:28 Z Farrius 슈퍼트리 잇기 (IOI20_supertrees) C++14
21 / 100
274 ms 24172 KB
#include "supertrees.h"
#include <vector>

using namespace std;

struct DSU {
	vector<int> e;
	void init (int n) {e = vector<int>(n, -1);}
	int get (int x) {return e[x] < 0 ? x : e[x] = get(e[x]);}
	bool sameSet (int x, int y) {return get(x) == get(y);}
	bool unite (int x, int y) {
		x = get(x), y = get(y);
		if (x == y) return false;
		if (e[x] > e[y]) swap(x, y);
		e[x] += e[y];
		e[y] = x;
		return true;
	}
};

int construct(vector<vector<int>> p) {
	//take input
	int n = p.size();
	vector<vector<int>> sol(n, vector<int>(n));
	DSU dsu;
	dsu.init(n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (p[i][j] >= 1) {
				dsu.unite(i, j);
			}
		}
	}
	//comprovar si ok
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (p[i][j] == 0 && dsu.sameSet(i, j)) return 0;
		}
	}
	//crear graph con los componentes creados
	vector<int> g[n];
	for (int i = 0; i < n; i++) {
		int par = dsu.get(i);
		g[par].push_back(i);
	}
	//crear la sol haciendo trees con los cc
	for (int i = 0; i < n; i++) {
		if ((int) g[i].size() < 2) continue;
		for (int j = 1; j < (int) g[i].size(); j++) {
			sol[g[i][j - 1]][g[i][j]] = 1;
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (sol[i][j] == 1) sol[j][i] = 1;
		}
	}
	//output
	build(sol);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 16 ms 1260 KB Output is correct
7 Correct 274 ms 23020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 16 ms 1260 KB Output is correct
7 Correct 274 ms 23020 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 10 ms 1260 KB Output is correct
13 Correct 243 ms 24044 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 6 ms 876 KB Output is correct
17 Correct 121 ms 14072 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
20 Correct 61 ms 6252 KB Output is correct
21 Correct 261 ms 24044 KB Output is correct
22 Correct 243 ms 24172 KB Output is correct
23 Correct 267 ms 24044 KB Output is correct
24 Correct 244 ms 24044 KB Output is correct
25 Correct 112 ms 14188 KB Output is correct
26 Correct 108 ms 14060 KB Output is correct
27 Correct 267 ms 24172 KB Output is correct
28 Correct 239 ms 24044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Incorrect 0 ms 364 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Incorrect 0 ms 364 KB Too few ways to get from 0 to 1, should be 2 found 1
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 16 ms 1260 KB Output is correct
7 Correct 274 ms 23020 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 10 ms 1260 KB Output is correct
13 Correct 243 ms 24044 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 6 ms 876 KB Output is correct
17 Correct 121 ms 14072 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
20 Correct 61 ms 6252 KB Output is correct
21 Correct 261 ms 24044 KB Output is correct
22 Correct 243 ms 24172 KB Output is correct
23 Correct 267 ms 24044 KB Output is correct
24 Correct 244 ms 24044 KB Output is correct
25 Correct 112 ms 14188 KB Output is correct
26 Correct 108 ms 14060 KB Output is correct
27 Correct 267 ms 24172 KB Output is correct
28 Correct 239 ms 24044 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 0 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Incorrect 0 ms 364 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 16 ms 1260 KB Output is correct
7 Correct 274 ms 23020 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 10 ms 1260 KB Output is correct
13 Correct 243 ms 24044 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 6 ms 876 KB Output is correct
17 Correct 121 ms 14072 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
20 Correct 61 ms 6252 KB Output is correct
21 Correct 261 ms 24044 KB Output is correct
22 Correct 243 ms 24172 KB Output is correct
23 Correct 267 ms 24044 KB Output is correct
24 Correct 244 ms 24044 KB Output is correct
25 Correct 112 ms 14188 KB Output is correct
26 Correct 108 ms 14060 KB Output is correct
27 Correct 267 ms 24172 KB Output is correct
28 Correct 239 ms 24044 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 0 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Incorrect 0 ms 364 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -