Submission #1078757

# Submission time Handle Problem Language Result Execution time Memory
1078757 2024-08-28T05:53:57 Z Faisal_Saqib Connecting Supertrees (IOI20_supertrees) C++17
0 / 100
1000 ms 24100 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]=i;
}
int get(int x)
{
	if(par[x]==x)return x;
	return par[x]=get(par[x]);
}
bool merge(int x,int y)
{
	x=get(x);
	y=get(y);
	if(x==y)return 0;
	par[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++)
	{
		for(int j=0;j<n;j++)
		{
			two|=(p[i][j]==2);
			tree_case[i][j]=reach[i][j]=0;
		}
	}
	if(two)
	{
		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);
					}
				}
				component.push_back(component[0]);
				for(int i=1;i<component.size();i++)
				{
					tree_case[component[i-1]][component[i]]=1;
					tree_case[component[i]][component[i-1]]=1;
				}
			}
		}
	}
	else
	{		
		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]=merge(i,j);
				}
			}
		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;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 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:71:18: 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=1;i<component.size();i++)
      |                 ~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 15 ms 2908 KB Output is correct
7 Execution timed out 1075 ms 24100 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 15 ms 2908 KB Output is correct
7 Execution timed out 1075 ms 24100 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 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 344 KB Answer gives possible 0 while actual possible 1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 15 ms 2908 KB Output is correct
7 Execution timed out 1075 ms 24100 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 15 ms 2908 KB Output is correct
7 Execution timed out 1075 ms 24100 KB Time limit exceeded
8 Halted 0 ms 0 KB -