답안 #470403

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
470403 2021-09-03T16:45:35 Z jazzup 슈퍼트리 잇기 (IOI20_supertrees) C++14
0 / 100
0 ms 204 KB
#include "supertrees.h"
#include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;

int par[1010];
vector<int> heads;

int findPar(int n){
	if(par[n]==n)return n;

	return par[n]=findPar(par[n]);
}

bool c[1010];
vector<vector<int> > answer;

int construct(vector<vector<int> > p) {
	int n = p.size();
	for(int i=0;i<=n;i++){
		par[i]=i;
	}
	
	

	for(int i=0;i<n;i++){
		vector<int> vv;
		answer.push_back(vv);
		for(int j=0;j<n;j++){
			answer[i].push_back(0);
		}
	}
	
	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;

			if(p[i][j]==1){
				par[max(i,j)]=findPar(min(i,j));
				answer[j][par[j]]=1;
				answer[par[j]][j]=1;
			}
		}
	}

	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(i==j)continue;
			if(p[i][j]==2){
				if(findPar(i)==findPar(j)){
					return 0;
				}

				c[findPar(i)]=true;
				c[findPar(j)]=true;
			}

			else if(p[i][j]==0){
				if(findPar(i)==findPar(j)){
					return 0;
				}
			}
		}
	}

	for(int i=0;i<n;i++){
		if(c[i])heads.push_back(i);
	}

	if(!heads.empty()){
		for(int i=0;i<heads.size()-1;i++){
			answer[heads[i]][heads[i+1]]=1;
			answer[heads[i+1]][heads[i]]=1;
		}
	
		answer[heads[heads.size()-1]][heads[0]]=1;
		answer[heads[0]][heads[heads.size()-1]]=1;
	}

	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:73:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |   for(int i=0;i<heads.size()-1;i++){
      |               ~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB b[0][0] is not 0
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB b[0][0] is not 0
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Incorrect 0 ms 204 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB b[1][1] is not 0
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB b[0][0] is not 0
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB b[0][0] is not 0
3 Halted 0 ms 0 KB -