Submission #837864

# Submission time Handle Problem Language Result Execution time Memory
837864 2023-08-25T19:07:42 Z mathematik Connecting Supertrees (IOI20_supertrees) C++17
Compilation error
0 ms 0 KB
#include "supertrees.h"
#include <bits/stdc++.h>

using namespace std;

struct setunion{
	int N;
	vector<int> p, s;

	setunion(int n) {
		N = n;
		p = vector<int>(n, -1);
		s = vector<int>(n, 1);
	}

	int root(int n) {
		int i = n;
		while (p[i] != -1)
			i = p[i];
		p[n] = i;
		return i;
	}

	int combine(int a, int b) {
		int ra = root(a), rb = root(b);

		if (ra == rb) return;

		if (s[ra] < s[rb]) swap(ra, rb);

		s[ra] += s[rb];
		p[rb] = ra;
	}

	vector<vector<int>> extract() {
		vector<vector<int>> erg(N), rem;
		for (int i = 0; i < N; i++)
		{
			erg[root(i)].push_back(i);
		}
		for (vector<int> e: erg)
			if (e.size())
				rem.push_back(e);
		return rem;
	}
};

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

	int c = 0, o = 0;

	setunion zsm(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]) zsm.combine(i, j);
			if (p[i][j] || i == j) o++;
			if (p[i][j] || i == j) c++;
		}
	}
	
	vector<vector<int>> graph = vector<vector<int>>(N, vector<int>(N));
	for (vector<int> z: zsm.extract()) {
		c -= z.size() * z.size();

		setunion one(z.size());
		for (int i: z)
		{
			for (int j: z)
			{
				if (p[i][j] == 1)
					one.combine(i, j);
			}
		}
		
		vector<vector<int>> g = one.extract();

		for (int i = 0; i < g.size(); i++)
		{
			graph[g[i][0]][g[(i + 1) % g.size()][0]] = true;
			graph[g[(i + 1) % g.size()][0]][g[i][0]] = true;
		}
		
		for (int i = 0; i < g.size(); i++)
		{
			o -= g[i].size() * g[i].size();
			for (int j = 1; j < g[i].size(); j++)
			{
				graph[g[i][0]][g[i][j]] = true;
			}
		}
	}

	if (c || o) return 0;

	build(graph);

	return 1;
}

Compilation message

supertrees.cpp: In member function 'int setunion::combine(int, int)':
supertrees.cpp:27:17: error: return-statement with no value, in function returning 'int' [-fpermissive]
   27 |   if (ra == rb) return;
      |                 ^~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:81:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |   for (int i = 0; i < g.size(); i++)
      |                   ~~^~~~~~~~~~
supertrees.cpp:87:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |   for (int i = 0; i < g.size(); i++)
      |                   ~~^~~~~~~~~~
supertrees.cpp:90:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |    for (int j = 1; j < g[i].size(); j++)
      |                    ~~^~~~~~~~~~~~~
supertrees.cpp: In member function 'int setunion::combine(int, int)':
supertrees.cpp:32:9: warning: control reaches end of non-void function [-Wreturn-type]
   32 |   p[rb] = ra;