이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "supertrees.h"
#include <vector>
int pp[1001][1001];
int n;
std::vector<std::vector<int>> answer;
bool all1()
{
	int i, j;
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			if (pp[i][j] != 1)
				return false;
	return true;
}
bool all01()
{
	int i, j;
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			if (pp[i][j] > 1)
				return false;
	return true;
}
void solve1()
{
	int i;
	for (i = 0; i < n - 1; i++) {
		answer[i][i + 1] = 1;
		answer[i + 1][i] = 1;
	}
}
int color[1001];
int nodes[1001];
int nn;
bool flag2;
void dfs(int u, int prnt)
{
	int j;
//	if (prnt == -1) {
//		std::vector<int> v;
//		for (j = 0; j < n; j++)
//			if (pp[u][j])
//				v.push_back(j);
//		for (j = 0; j < v.size() - 1; j++)
//			if (!pp[v[j]][v[j + 1]])
//				flag2 = false;
//		if (v.size() > 1 && !pp[v[0]][v.size() - 1])
//			flag2 = false;
//	}
	for(j=0; j<n; j++)
		if (pp[u][j] && !color[j]) {
			nodes[nn++] = j;
			color[j] = 1;
//			if (prnt != -1 && !pp[j][prnt])
//				flag2 = false;
			dfs(j, u);
		}
}
void solve2()
{
	int i, j;
	for (i = 0; i < n; i++) {
		if (!color[i]) {
			nn = 0;
			color[i] = 1;
			dfs(i, -1);
			for (j = 1; j < nn; j++) {
				answer[nodes[j]][nodes[j - 1]] = 1;
				answer[nodes[j - 1]][nodes[j]] = 1;
			}
		}
	}
}
int construct(std::vector<std::vector<int>> p)
{
	n = p.size();
	int i, j, k;
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++) {
			if (i == j)
				continue;
			if (p[i][j]) {
				for (k = 0; k < n; k++) {
					if (k == i || k == j)
						continue;
					if (p[j][k] && !p[i][k])
						return 0;
				}
			}
		}
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			pp[i][j] = p[i][j];
	for (int i = 0; i < n; i++) {
		std::vector<int> row;
		row.resize(n);
		answer.push_back(row);
	}
	if (all1())
		solve1();
	else if (all01()) {
//		flag2 = true;
		solve2();
//		if (flag2) {
//			build(answer);
//			return 1;
//		}
//		else
//			return 0;
	}
	build(answer);
	return 1;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |