Submission #470282

# Submission time Handle Problem Language Result Execution time Memory
470282 2021-09-03T11:24:05 Z jazzup Connecting Supertrees (IOI20_supertrees) C++14
0 / 100
1 ms 332 KB
#include"supertrees.h"
#include<vector>

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];

int construct(vector<vector<int> > p) {
	int n = p.size();
	vector<vector<int> > answer;
	for (int i = 0; i < n; i++) {
		vector<int> row;
		row.resize(n);
		answer.push_back(row);
	}

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

	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			if(p[i][j]==3)return 0;

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

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

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

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

	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:61:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |  for(int i=0;i<heads.size()-1;i++){
      |              ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -