답안 #788225

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
788225 2023-07-20T02:49:28 Z mindiyak 슈퍼트리 잇기 (IOI20_supertrees) C++14
11 / 100
168 ms 23936 KB
#include "supertrees.h"
#include <vector>
#include <set>
#include <iostream>

using namespace std;

vector<int> parent(1003);

int find_head(int n){
	if(parent[n] == n){
		return n;
	}return find_head(parent[n]);
}

int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	set<int> heads;
	vector<vector<int>>ans(n,vector<int>(n,0));

	for (int i = 0; i < n; i++) {
		parent[i] = i;
	}

	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(i==j)
				continue;
			if(p[i][j] == 3){
				return 0;
			}else if(p[i][j] == 1){
				int lower = min(i,j);
				int higher = max(i,j);
				if(find_head(lower) != find_head(higher)){
					ans[i][j] = 1;
					ans[j][i] = 1;
					parent[higher] = find_head(lower);
				}
			}else if(p[i][j] == 2){
				heads.insert(find_head(i));
				heads.insert(find_head(j));
			}
		}
	}

	// cout << "table travers" << endl;

	vector<int> header;
	for (int i : heads) {
		header.push_back(i);
	}


	int t = header.size();

	// cout << t << " " << (0<(t-1)) << endl;

	for (int i = 0; i < (t-1); i++) {
		// cout << "for" << endl;
		ans[header[i]][header[i+1]] = 1;
		ans[header[i+1]][header[i]] = 1;
	}
	if(t > 2){
		// cout << "comare" << endl;
		ans[header[0]][header[t-1]] = 1;
		ans[header[t-1]][header[0]] = 1;
	}

	// cout << "headers connected" << endl;

	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			int i_head = find_head(i);
			int j_head = find_head(j);
			if(i==j)
				continue;
			if(p[i][j] == 1){
				if(heads.count(i_head) == 1 and heads.count(j_head) == 1 and i_head != j_head){
					// cout << i << " " << j << " " << i_head << " " << j_head << " " <<
					return 0;
				}
				if(i_head != j_head){
					return 0;
				}
			}else if(p[i][j] == 2){
				if(heads.count(i_head) == 0 or heads.count(j_head) == 0){
					return 0;
				}
			}
		}
	}


	build(ans);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 168 ms 23904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 168 ms 23904 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 9 ms 1236 KB Output is correct
13 Correct 157 ms 23912 KB Output is correct
14 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 45 ms 6156 KB Output is correct
5 Correct 155 ms 23928 KB Output is correct
6 Correct 167 ms 23912 KB Output is correct
7 Correct 161 ms 23936 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Incorrect 39 ms 6264 KB Too many ways to get from 0 to 1, should be 0 found no less than 1
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 168 ms 23904 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 9 ms 1236 KB Output is correct
13 Correct 157 ms 23912 KB Output is correct
14 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 168 ms 23904 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 9 ms 1236 KB Output is correct
13 Correct 157 ms 23912 KB Output is correct
14 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -