Submission #301561

# Submission time Handle Problem Language Result Execution time Memory
301561 2020-09-18T04:28:36 Z jwvg0425 Connecting Supertrees (IOI20_supertrees) C++17
0 / 100
1 ms 256 KB
#include "supertrees.h"
#include <vector>

using namespace std;

int cpar[1005];
int tpar[1005];

int tfind(int x)
{
	if (tpar[x] == x)
		return x;

	return tpar[x] = tfind(tpar[x]);
}

void tmerge(int x, int y)
{
	x = tfind(x);
	y = tfind(y);

	tpar[x] = y;
}

int cfind(int x)
{
	if (cpar[x] == x)
		return x;

	return cpar[x] = cfind(cpar[x]);
}

void cmerge(int x, int y)
{
	x = cfind(x);
	y = cfind(y);

	cpar[x] = y;
}

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

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

	vector<vector<int>> answer;
	for (int i = 0; i < n; i++)
	{
		vector<int> row;
		row.resize(n);
		answer.push_back(row);
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			if (p[i][j] == 0)
				continue;

			if (p[i][j] == 1)
			{
				if (tfind(i) == tfind(j))
					continue;

				tmerge(i, j);
				answer[i][j] = answer[j][i] = 1;
				continue;
			}

			if (p[i][j] == 2)
				cmerge(i, j);
		}
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			if (p[i][j] == 0)
			{
				if (cfind(i) == cfind(j) || tfind(i) == tfind(j))
					return 0;
			}

			if (p[i][j] == 1)
			{
				if (cfind(i) == cfind(j) || tfind(i) != tfind(j))
					return 0;
			}

			if (p[i][j] == 2)
			{
				if (cfind(i) != cfind(j) || tfind(i) == tfind(j))
					return 0;
			}
		}
	}

	for (int i = 0; i < n; i++)
	{
		if (cfind(i) != i)
			continue;

		vector<int> cs;

		for (int j = 0; j < n; j++)
			if (cfind(j) == i)
				cs.push_back(j);

		for (int x = 0; x < cs.size(); x++)
		{
			int nx = (x + 1) % cs.size();
			answer[cs[x]][cs[nx]] = answer[cs[nx]][cs[x]] = 1;
		}
	}

	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:113:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  113 |   for (int x = 0; x < cs.size(); x++)
      |                   ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 256 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -