Submission #470429

# Submission time Handle Problem Language Result Execution time Memory
470429 2021-09-03T18:02:45 Z jazzup Connecting Supertrees (IOI20_supertrees) C++14
Compilation error
0 ms 0 KB
#include "supertrees.h"
#include <vector>
#include <cstdio>

using namespace std;

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

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-1;i++){
		for(int j=i+1;j<n;j++){
			if(p[i][j]!=p[j][i])return 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){
				if(findPar(i)<findPar(j)){
					par[findPar(j)]=findPar(i);
					answer[j][findPar(j)]=1;
					answer[findPar(j)][j]=1;
				}
				else if(findPar(i)>findPar(j)){
					par[findPar(i)]=findPar(j);
					answer[i][findPar(i)]=1;
					answer[findPar(i)][i]=1;
				}
			}
		}
	}

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

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

				if(findPar(i)<findPar(j)){
					par[findPar(j)]=findPar(i);
				}
				else if(findPar(i)>findPar(j)){
					par[findPar(i)]=findPar(j);
				}

				heads[findPar(i)].push_back(i);
				heads[findPar(j)].push_back(j);
			}
		}
	}

	for(int h=0;h<n;h++){
		sort(heads[h].begin(),heads[h].end());
		unique(heads[h].begin(),heads[h].end());
		if(!heads[h].empty()){
			for(int i=0;i<heads[h].size()-1;i++){
				answer[heads[h][i]][heads[h][i+1]]=1;
				answer[heads[h][i+1]][heads[h][i]]=1;
			}
		
			answer[heads[h][heads[h].size()-1]][heads[h][0]]=1;
			answer[heads[h][0]][heads[h][heads[h].size()-1]]=1;
		}

		if(heads[h].size()==2)return 0;
	}

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

	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:82:3: error: 'sort' was not declared in this scope; did you mean 'short'?
   82 |   sort(heads[h].begin(),heads[h].end());
      |   ^~~~
      |   short
supertrees.cpp:83:3: error: 'unique' was not declared in this scope
   83 |   unique(heads[h].begin(),heads[h].end());
      |   ^~~~~~
supertrees.cpp:85:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |    for(int i=0;i<heads[h].size()-1;i++){
      |                ~^~~~~~~~~~~~~~~~~~