Submission #302140

#TimeUsernameProblemLanguageResultExecution timeMemory
302140Bill_00Connecting Supertrees (IOI20_supertrees)C++14
0 / 100
1 ms896 KiB
#include "supertrees.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
int u[10001];
vector<int>v[10001];
int construct(vector<vector<int> > p) {
	int n = p.size();
	vector<vector<int> > answer;
	answer.resize(n);
	for (int i = 0; i < n; i++) {
		vector<int> row;
		row.resize(n);
		for(int j=0;j<n;j++){
			row[j]=0;
		}
		answer[i]=row;
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(p[i][j]==3){
				return 0;
			}
		}
	}
	int o=0;
	for(int i=0;i<n;i++){
		for(int j=i;j<n;j++){
			if(u[i]!=u[j] && p[i][j]!=0){
				return 0;
			}
		}
		if(u[i]==0){
			o++;
			u[i]=o;
		} 
		for(int j=i;j<n;j++){
			if(p[i][j]!=0){
				u[j]=u[i];
			}
		}
	}
	for(int i=0;i<n;i++){
		v[u[i]].push_back(i);
	}
	for(int i=1;i<=o;i++){
		vector<int>group;
		vector<int>core;
      	if(v[i].size()==1) continue;
		for(int j=0;j<v[i].size();j++){
			int flag=0;
			for(int k=0;k<v[i].size();k++){
				if(j==k) continue;
				if(p[v[i][j]][v[i][k]]==1){
					flag++;
				}
			}
			if(flag){
				group.push_back(v[i][j]);
			}
			else core.push_back(v[i][j]);
		}
		for(int j=0;j<group.size();j++){
			for(int k=0;k<group.size();k++){
				if(p[group[j]][group[k]]==2) return 0;
			}
		}
		if(group.size()>0) core.push_back(group[0]);
		for(int j=0;j<group.size()-1;j++){
			answer[group[j]][group[j+1]]=1;
			answer[group[j+1]][group[j]]=1;
		}
      	if(core.size()==2) return 0;
		for(int j=0;j<core.size();j++){
			answer[core[j]][core[(j+1)%(core.size())]]=1;
			answer[core[(j+1)%(core.size())]][core[j]]=1;		
		}
	}
	build(answer);
	return 1;
}

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:50:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |   for(int j=0;j<v[i].size();j++){
      |               ~^~~~~~~~~~~~
supertrees.cpp:52:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |    for(int k=0;k<v[i].size();k++){
      |                ~^~~~~~~~~~~~
supertrees.cpp:63:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |   for(int j=0;j<group.size();j++){
      |               ~^~~~~~~~~~~~~
supertrees.cpp:64:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |    for(int k=0;k<group.size();k++){
      |                ~^~~~~~~~~~~~~
supertrees.cpp:69:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |   for(int j=0;j<group.size()-1;j++){
      |               ~^~~~~~~~~~~~~~~
supertrees.cpp:74:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |   for(int j=0;j<core.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...