Submission #301702

# Submission time Handle Problem Language Result Execution time Memory
301702 2020-09-18T06:19:07 Z Muhammetali Connecting Supertrees (IOI20_supertrees) C++14
0 / 100
1 ms 256 KB
#include "supertrees.h"
#include <bits/stdc++.h>
#define mp make_pair
#define f first
#define s second
#define sz(x) (int)(x).size()
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
vi get_comp(vector<vi>& adj,vector<bool>& vis,int k)
{
	assert(!vis[k]);
	vis[k]=1;
	vi comp(1,k);
	for (int i=0;i<sz(comp);i++)
	{
		assert(vis[comp[i]]);
		for (int j:adj[comp[i]])
		{
			if (!vis[j])
			{
				vis[j]=1;
				comp.pb(j);
			}
		}
	}
	return comp;
}
int construct(vector<vi> p)
{
	int n=sz(p);
	vector<vi> ans(n,vi(n));
	vector<vi> adjtree(n),adjcycl(n);
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<n;j++)
		{
			if (p[i][j]==3)return 0;
			if (p[i][j]==1)adjtree[i].pb(j);
		}
	}
	vector<vi>trees;
	vi roots;
	vector<bool> vis(n);
	for (int i=0;i<n;i++)
	{
		if (!vis[i])
		{
			trees.pb(get_comp(adjtree,vis,i));
			roots.pb(trees.bk.bk);
		}
	}
	for (int i=0;i<sz(trees);i++)
	{
		for (int j=0;j<sz(trees);j++)
		{
			int k=p[roots[i]][roots[j]];
			if (k==0 && i==j)return 0;
			if (k==1 && i!=j)return 0;
			if (k==2 && i==j)return 0;
			for (int k:trees[i])
			{
				for (int l:trees[j])
				{
					if (p[k][l]!=k)return 0;
				}
			}
		}
	}
	for (auto& i:trees)
	{
		for (int j=1;j<sz(i);j++)
		{
			ans[i[0]][i[j]]=1;
		}
	}
	for (int i:roots)
	{
		for (int j:roots)
		{
			if (p[i][j]==2)adjcycl[i].pb(j);
		}
	}
	vis=vector<bool>(n);
	for (int i:roots)
	{
		if (!vis[i])
		{
			vi v=get_comp(adjcycl,vis,i);
			for (int i:v)
			{
				for (int j:v)
				{
					if (p[i][j]!=2 && i!=j)return 0;
				}
			}
			if (sz(v)>1)
			{
				for (int k=0,l=sz(v)-1;k<sz(v);l=k++)
				{
                    ans[v[k]][v[l]] = 1;
                }
			}
			if (sz(v)==2)return 0;
		}
	}
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<n;j++)
		{
			ans[i][j]|=ans[j][i];
			ans[j][i]|=ans[i][j];
		}
	}
	for (int i=0;i<n;i++)ans[i][i]=0;
	build(ans);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 256 KB Answer gives possible 0 while actual possible 1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 256 KB Answer gives possible 0 while actual possible 1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Answer gives possible 0 while actual possible 1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 256 KB Answer gives possible 0 while actual possible 1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 256 KB Answer gives possible 0 while actual possible 1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 256 KB Answer gives possible 0 while actual possible 1
2 Halted 0 ms 0 KB -