Submission #384740

#TimeUsernameProblemLanguageResultExecution timeMemory
384740nicholaskConnecting Supertrees (IOI20_supertrees)C++14
100 / 100
264 ms22380 KiB
#include "supertrees.h"
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
int construct(vector <vector <int> > p){
	int n=p.size();
	vector <vector <int> > ans(n,vector<int>(n,0));
	vector <pair <int,vector <int> > > ones;
	for (int i=0; i<n; i++){
		for (int j=0; j<n; j++){
			if (p[i][j]==3) return 0;
		}
	}
	bool d[n];
	int cnt=0;
	int belong[n];
	for (int i=0; i<n; i++) d[i]=0;
	for (int i=0; i<n; i++){
		if (d[i]) continue;
		vector <int> v;
		for (int j=i; j<n; j++){
			if (p[i][j]==1){
				if (d[j]) return 0;
				d[j]=1;
				v.push_back(j);
			}
		}
		for (int j=0; j<v.size()-1; j++) ans[v[j]][v[j+1]]=1;
		ones.push_back({cnt,v});
		for (auto&j:v) belong[j]=cnt;
		cnt++;
	}
	cnt=0;
	int bigbelong[n];
	for (int i=0; i<n; i++) bigbelong[i]=0;
	int nway[n];
	for (int i=0; i<n; i++) nway[i]=0;
	bool e[ones.size()];
	for (int i=0; i<ones.size(); i++) e[i]=0;
	for (int i=0; i<ones.size(); i++){
		if (e[i]) continue;
		vector <int> temp;
		temp.push_back(ones[i].y.front());
		for (auto&j:ones[i].y) bigbelong[j]=cnt;
		for (int j=i+1; j<ones.size(); j++){
			if (!e[j]&&p[ones[i].y.front()][ones[j].y.front()]==2){
				temp.push_back(ones[j].y.front());
				for (auto&k:ones[j].y) bigbelong[k]=cnt;
				e[j]=1;
			}
		}
		int ss=temp.size();
		if (ss<3){
			nway[cnt]=1;
			cnt++;
			continue;
		}
		for (int j=0; j<temp.size(); j++) ans[temp[j]][temp[(j+1)%ss]]=1;
		nway[cnt]=2;
		cnt++;
	}
	for (int i=0; i<n; i++){
		for (int j=i+1; j<n; j++){
			if (p[i][j]==0){
				if (bigbelong[i]==bigbelong[j]) return 0;
			} else if (p[i][j]==1){
				if (belong[i]!=belong[j]&&(bigbelong[i]!=bigbelong[j]||nway[bigbelong[i]]!=1)) return 0;
			} else if (p[i][j]==2){
				if (belong[i]==belong[j]||bigbelong[i]!=bigbelong[j]||nway[bigbelong[i]]!=2) return 0;
			}
		}
	}
	for (int i=0; i<n; i++){
		for (int j=0; j<n; j++){
			if (ans[j][i]) ans[i][j]=1; 
		}
	}
	build(ans);
	return 1;
}

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:29:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   for (int j=0; j<v.size()-1; j++) ans[v[j]][v[j+1]]=1;
      |                 ~^~~~~~~~~~~
supertrees.cpp:40:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::vector<int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |  for (int i=0; i<ones.size(); i++) e[i]=0;
      |                ~^~~~~~~~~~~~
supertrees.cpp:41:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::vector<int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |  for (int i=0; i<ones.size(); i++){
      |                ~^~~~~~~~~~~~
supertrees.cpp:46:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::vector<int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |   for (int j=i+1; j<ones.size(); j++){
      |                   ~^~~~~~~~~~~~
supertrees.cpp:59:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |   for (int j=0; j<temp.size(); j++) ans[temp[j]][temp[(j+1)%ss]]=1;
      |                 ~^~~~~~~~~~~~
#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...