제출 #362705

#제출 시각아이디문제언어결과실행 시간메모리
362705abra_stone슈퍼트리 잇기 (IOI20_supertrees)C++14
21 / 100
305 ms28268 KiB
#include "supertrees.h"
#include <vector>
#define N 1005
using namespace std;

int n, gc, gr[N], pa[N], a[N][N];
vector<int> rt;
vector<vector<int> > answer;

int uni(int p) {
	if (pa[p] == p) return p;
	else return pa[p] = uni(pa[p]);
}

void make_tree(int p) {
	int i;
	gr[p] = gc;
	for (i = 0; i < n; i++) {
		if (a[p][i] != 1 || gr[i]) continue;
		answer[p][i] = answer[i][p] = 1;
		pa[uni(i)] = uni(p);
		make_tree(i);
	}
}

int construct(std::vector<std::vector<int> > P) {
	n = P.size();
	int i, j;
	vector<int> t;
	t.clear();
	for (i = 0; i < n; i++) t.push_back(0);
	for (i = 0; i < n; i++) answer.push_back(t);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			a[i][j] = P[i][j];
			if (a[i][j] == 3) return 0;
		}
	}
	for (i = 0; i < n; i++) pa[i] = i;

	for (i = 0; i < n; i++) {
		if (!gr[i]) {
			gc++;
			rt.push_back(i);
			make_tree(i);
		}
	}
	for (i = 0; i < n; i++) {
		for (j = i + 1; j < n; j++) {
			if (gr[i] == gr[j] && a[i][j] != 1) return 0;
			if (gr[i] != gr[j] && a[i][j] == 1) return 0;
		}
	}

	for (i = 0; i < rt.size(); i++) {
		for (j = i + 1; j < rt.size(); j++) {
			if (a[rt[i]][rt[j]] == 2) {
				pa[uni(rt[i])] = uni(rt[j]);
				answer[rt[i]][rt[j]] = answer[rt[j]][rt[i]] = 1;
			}
		}
	}
	for (i = 0; i < n; i++) {
		for (j = i + 1; j < n; j++) {
			if (uni(i) == uni(j) && a[i][j] == 0) return 0;
			if (uni(i) != uni(j) && a[i][j] != 0) return 0;
		}
	}
	build(answer);
	return 1;
}

컴파일 시 표준 에러 (stderr) 메시지

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:55:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |  for (i = 0; i < rt.size(); i++) {
      |              ~~^~~~~~~~~~~
supertrees.cpp:56:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |   for (j = i + 1; j < rt.size(); j++) {
      |                   ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...