답안 #1078781

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1078781 2024-08-28T06:13:05 Z Faisal_Saqib 슈퍼트리 잇기 (IOI20_supertrees) C++17
컴파일 오류
0 ms 0 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int N=1e3;
int reach[N][N],tree_case[N][N];
int par[N];
void init(int n)
{
	for(int i=0;i<n;i++)
		par[i]=par1[i]=i;
}
int get(int x)
{
	if(par[x]==x)return x;
	return par[x]=get(par[x]);
}
int get1(int x)
{
	if(par1[x]==x)return x;
	return par1[x]=get1(par1[x]);
}
bool merge(int x,int y)
{
	x=get(x);
	y=get(y);
	if(x==y)return 0;
	par[y]=x;
	return 1;
}
bool merge1(int x,int y)
{
	x=get1(x);
	y=get1(y);
	if(x==y)return 0;
	par1[y]=x;
	return 1;
}
vector<int> ma[N];
int head;
void dfs(int x)
{
	reach[head][x]=1;
	for(auto y:ma[x])
		if(!reach[head][y])
			dfs(y);
}
int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	init(n);
	bool two=0;
	for(int i=0;i<n;i++)
	{
		if(p[i][i]!=1) // i i is always one
			return 0;
		for(int j=0;j<n;j++)
		{
			two|=(p[i][j]==2);
			tree_case[i][j]=reach[i][j]=0;
		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			if(p[i][j]==2)
			{
				merge(i,j);
			}
		}
	}
	for(int i=0;i<n;i++)
	{
		if(get(i)==i)
		{
			vector<int> component;
			for(int j=0;j<n;j++)
			{
				if(get(j)==i)
				{
					component.push_back(j);
				}
			}
			if(component.size()==1)continue;
			if(component.size()==2)
				return 0;
			component.push_back(component[0]);
			for(int i=1;i<component.size();i++)
			{
				int x=component[i-1];
				int y=component[i];
				tree_case[x][y]=1;
				tree_case[y][x]=1;
				merge1(x,y);
			}
		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			if(p[i][j]==1)
			{
				tree_case[i][j]=tree_case[j][i]=merge1(i,j);
			}
		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{	
			if(tree_case[i][j])
			{
				ma[i].push_back(j);
				ma[j].push_back(i);
			}
		}
	}
	vector<vector<int>> answer(n,vector<int>(n,0));
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			answer[i][j]=tree_case[i][j];
			reach[i][j]=0;
		}
		head=i;
		dfs(i);
		for(int j=0;j<n;j++)
		{
			p[i][j]-=(p[i][j]==2);// make 2 to 1
			if(reach[i][j]!=p[i][j])
			{
				return 0;
			}
		}
	}
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'void init(int)':
supertrees.cpp:10:10: error: 'par1' was not declared in this scope; did you mean 'par'?
   10 |   par[i]=par1[i]=i;
      |          ^~~~
      |          par
supertrees.cpp: In function 'int get1(int)':
supertrees.cpp:19:5: error: 'par1' was not declared in this scope; did you mean 'par'?
   19 |  if(par1[x]==x)return x;
      |     ^~~~
      |     par
supertrees.cpp:20:9: error: 'par1' was not declared in this scope; did you mean 'par'?
   20 |  return par1[x]=get1(par1[x]);
      |         ^~~~
      |         par
supertrees.cpp: In function 'bool merge1(int, int)':
supertrees.cpp:35:2: error: 'par1' was not declared in this scope; did you mean 'par'?
   35 |  par1[y]=x;
      |  ^~~~
      |  par
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:87:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |    for(int i=1;i<component.size();i++)
      |                ~^~~~~~~~~~~~~~~~~