Submission #1002534

# Submission time Handle Problem Language Result Execution time Memory
1002534 2024-06-19T15:59:04 Z toast12 Connecting Supertrees (IOI20_supertrees) C++14
11 / 100
150 ms 24144 KB
#include "supertrees.h"
#include <vector>
#include <map>
#include <iostream>
using namespace std;

#define sz(x) (int)x.size()

struct DSU {
	int n;
	vector<int> link, size;
	DSU(int sz) {
		n = sz;
		link.resize(sz);
		size.resize(sz);
		for (int i = 0; i < n; i++) {
			link[i] = i;
			size[i] = 1;
		}
	}
	int find(int x) {
		while (x != link[x])
			x = link[x];
		return x;
	} 
	bool same(int a, int b) {
		return find(a) == find(b);
	}
	void unite(int a, int b) {
		a = find(a);
		b = find(b);
		if (a == b)
			return;
		if (size[a] < size[b])
			swap(a, b);
		link[b] = a;
		size[a] += size[b];
	}
};

int construct(std::vector<vector<int>> p) {
	int n = p.size();
	vector<vector<int>> answer(n, vector<int>(n));
	vector<vector<int>> c(n);
	DSU d(n+1);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i == j)
				continue;
			if (p[i][j]) {
				if (!d.same(i, j)) {
					d.unite(i, j);
					int x = d.find(i);
					c[x].push_back(j);
					c[x].push_back(i);
				}
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (sz(c[i]) <= 1)
			continue;
		vector<bool> done(n);
		vector<int> x;
		for (int j = 0; j < sz(c[i]); j++) {
			if (!done[c[i][j]])
				x.push_back(c[i][j]);
			done[c[i][j]] = true;
		}
		vector<int> one, two;
		for (int j = 0; j < sz(x); j++) {
			int r = x[j];
			bool o = false;
			for (int k = 0; k < n; k++) {
				if (k == r)
					continue;
				if (p[r][k] == 1) {
					o = true;
					break;
				}
			}
			if (!o)
				two.push_back(x[j]);
			else
				one.push_back(x[j]);
		}
		if (!one.empty()) {
			int temp = one.back();
			one.pop_back();
			two.push_back(temp);
		}
		for (int j = 0; j < sz(two)-1; j++) {
			answer[two[j]][two[j+1]] = 1;
			answer[two[j+1]][two[j]] = 1;
		}
		answer[two.back()][two[0]] = 1;
		answer[two[0]][two.back()] = 1;
		if (!one.empty()) {
			for (int j = 0; j < sz(one)-1; j++) {
				answer[one[j]][one[j+1]] = 1;
				answer[one[j+1]][one[j]] = 1;
			}
			answer[one.back()][two[0]] = 1;
			answer[two[0]][one.back()] = 1;
		}
	}
	for (int i = 0; i < n; i++) {
		answer[i][i] = 0;
	}
	build(answer);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1116 KB Output is correct
7 Correct 113 ms 22096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1116 KB Output is correct
7 Correct 113 ms 22096 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1116 KB Output is correct
13 Correct 112 ms 22096 KB Output is correct
14 Incorrect 0 ms 344 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 31 ms 6224 KB Output is correct
5 Correct 117 ms 23944 KB Output is correct
6 Correct 150 ms 24072 KB Output is correct
7 Correct 119 ms 23940 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 29 ms 6228 KB Output is correct
10 Correct 119 ms 24064 KB Output is correct
11 Correct 122 ms 23940 KB Output is correct
12 Correct 121 ms 24144 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Incorrect 0 ms 348 KB Too many ways to get from 0 to 4, should be 1 found no less than 2
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1116 KB Output is correct
7 Correct 113 ms 22096 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1116 KB Output is correct
13 Correct 112 ms 22096 KB Output is correct
14 Incorrect 0 ms 344 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1116 KB Output is correct
7 Correct 113 ms 22096 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1116 KB Output is correct
13 Correct 112 ms 22096 KB Output is correct
14 Incorrect 0 ms 344 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -