Submission #395119

#TimeUsernameProblemLanguageResultExecution timeMemory
395119T0p_Connecting Supertrees (IOI20_supertrees)C++14
0 / 100
1 ms204 KiB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;

int pa[2005], edge[1010][1010];
bool cycle[2005];

int fp(int u) {return (u == pa[u]) ? u : pa[u] = fp(pa[u]);}

int construct(vector<vector<int>> p)
{
	int n = p.size();

	for(int i=0 ; i<n+n ; i++)
		pa[i] = i;

	for(int i=0 ; i<n ; i++)
		for(int j=i+1 ; j<n ; j++)
		{
			if(p[i][j] == 3) return 0;
			else if(p[i][j])
			{
				pa[fp(i)] = fp(j);
				pa[fp(i+n)] = fp(j+n);
			}
			else
			{
				pa[fp(i)] = fp(j+n);
				pa[fp(i+n)] = fp(j);
			}
		}

	for(int i=0 ; i<n ; i++)
		if(fp(i) == fp(i+n)) return 0;

	for(int i=0 ; i<n ; i++)
	{
		vector<int> tmp;
		if(cycle[i]) continue;
		for(int j=0 ; j<n ; j++)
		{
			if(i == j) continue;
			if(p[i][j] == 1) goto out;
		}

		tmp.push_back(i);
		for(int j=0 ; j<n ; j++)
		{
			if(p[i][j] == 2) tmp.push_back(j);
		}
		tmp.push_back(i);

		if(tmp.size() < 4) return 0;
		
		for(int j=1 ; j<tmp.size() ; j++)
		{
			edge[tmp[j-1]][tmp[j]] = edge[tmp[j]][tmp[j-1]] = 1;
			cycle[tmp[j]] = true;
		}
		out: ;
	}
	vector<vector<int>> ans;
	for(int i=0 ; i<n ; i++)
	{
		vector<int> tmp;
		for(int j=0 ; j<n ; j++)
			tmp.push_back(edge[i][j]);
		ans.push_back(tmp);
	}
	build(ans);
	return 1;
}

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:55:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |   for(int j=1 ; j<tmp.size() ; j++)
      |                 ~^~~~~~~~~~~
#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...