Submission #301576

# Submission time Handle Problem Language Result Execution time Memory
301576 2020-09-18T04:54:08 Z Bill_00 Connecting Supertrees (IOI20_supertrees) C++14
Compilation error
0 ms 0 KB
#include "supertrees.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
int u[1001]={0};
int construct(std::vector<std::vector<int>> p) {
	std::vector<std::vector<int>> answer;
	for (int i = 0; i < n; i++) {
		std::vector<int> row;
		row.resize(n);
		for(int i=0;i<n;i++){
			row[i]=0;
		}
		answer.push_back(row);
	}
	int n = p.size();
	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];
			}
		}
	}
	vector<int>v[1001];
	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;
		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;
			}
		}
		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;
		}
		for(int i=0;i<core.size();i++){
			answer[core[i]][core[(i+1)%(core.size())]]=1;
			answer[core[(i+1)%(core.size())]][core[i]]=1;		
		}
	}
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:8:22: error: 'n' was not declared in this scope
    8 |  for (int i = 0; i < n; i++) {
      |                      ^
supertrees.cpp:48:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |   for(int j=0;j<v[i].size();j++){
      |               ~^~~~~~~~~~~~
supertrees.cpp:50:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |    for(int k=0;k<v[i].size();k++){
      |                ~^~~~~~~~~~~~
supertrees.cpp:61:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |   for(int j=0;j<group.size();j++){
      |               ~^~~~~~~~~~~~~
supertrees.cpp:62:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |    for(int k=0;k<group.size();k++){
      |                ~^~~~~~~~~~~~~
supertrees.cpp:67:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |   for(int j=0;j<group.size()-1;j++){
      |               ~^~~~~~~~~~~~~~~
supertrees.cpp:71:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |   for(int i=0;i<core.size();i++){
      |               ~^~~~~~~~~~~~