Submission #530726

#TimeUsernameProblemLanguageResultExecution timeMemory
530726ToroTNConnecting Supertrees (IOI20_supertrees)C++14
0 / 100
1 ms452 KiB
#include<bits/stdc++.h>
using namespace std;
#include "supertrees.h"
#include <vector>
int d[1005][1005],p1[1005],p2[1005],type,u,ans[1005][1005];
vector<int> v[1005],g[1005],kawin;
int f1(int a)
{
	if(p1[a]==a)
	{
		return a;
	}
	return p1[a]=f1(p1[a]);
}
void un1(int b,int c)
{
	p1[f1(b)]=f1(c);
}
int f2(int a)
{
	if(p2[a]==a)
	{
		return a;
	}
	return p2[a]=f2(p2[a]);
}
void un2(int b,int c)
{
	p2[f2(b)]=f2(c);
}
int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	std::vector<std::vector<int>> answer;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			d[i][j]=p[i-1][j-1];
		}
		p1[i]=i;
		p2[i]=i;
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(d[i][j]>=1)
			{
				un1(i,j);
			}
			if(d[i][j]==1)
			{
				un2(i,j);
			}
		}
	}
	/*for(int i=1;i<=n;i++)
	{
		printf("%d %d\n",p1[i],p2[i]);
	}*/
	type=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(f1(i)!=f1(j))
			{
				if(d[i][j]!=0)
				{
					type=-1;
				}
			}else
			{
				if(f2(i)==f2(j))
				{
					if(d[i][j]!=1)
					{
						type=-1;
					}
				}else
				{
					if(d[i][j]!=2)
					{
						type=-1;
					}
				}
			}
		}
	}
	//printf("%d\n",type);
	for(int i=1;i<=n;i++)
	{
		v[f2(i)].push_back(i);
		g[f1(i)].push_back(f2(i));
	}
	for(int i=1;i<=n;i++)
	{
		u=i;
		//printf("%d\n",i);
		for(int j=0;j<(int)v[i].size();j++)
		{
			//printf("%d ",v[i][j]);
			if(v[i][j]!=i)
			{
				ans[u][v[i][j]]=1;
				ans[v[i][j]][u]=1;
				u=v[i][j];
			}
		}
		//printf("\n");
		if(g[i].size()>=2)
		{
			for(int j=0;j<(int)g[i].size()-1;j++)
			{
				ans[g[i][j]][g[i][j+1]]=1;
				ans[g[i][j+1]][g[i][j]]=1;
			}
			ans[g[i][0]][g[i][g[i].size()-1]]=1;
			ans[g[i][g[i].size()-1]][g[i][0]]=1;
		}
	}
	/*for(int i=1;i<=n;i++)
	{
		ans[i][i]=1;
	}*/
	for(int i=1;i<=n;i++)
	{
		kawin.clear();
		for(int j=1;j<=n;j++)
		{
			kawin.push_back(ans[i][j]);
		}
		answer.push_back(kawin);
	}
	if(type==-1)
	{
		return 0;
	}
	build(answer);
	return 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...