Submission #300197

# Submission time Handle Problem Language Result Execution time Memory
300197 2020-09-17T00:19:19 Z VladaMG98 Connecting Supertrees (IOI20_supertrees) C++17
0 / 100
254 ms 24568 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;

struct dsu {
	int n;
	vector<int> parent, rank;
	dsu(int _n) {
		n = _n;
		parent.resize(n);
		rank.resize(n);
		for (int i = 0; i < n; i++) {
			parent[i] = i;
			rank[i] = 1;
		}
	}
	int get(int x) {
		if (parent[x] == x) return x;
		return parent[x] = get(parent[x]);
	}
	bool unite(int x, int y) {
		x = get(x), y = get(y);
		if (x == y) return false;
		if (rank[x] < rank[y]) swap(x, y);
		parent[y] = x;
		rank[x] += rank[y];
		return true;
	}
	vector<int> all_roots() {
		set<int> s;
		for (int i = 0; i < n; i++) s.insert(parent[i]);
		vector<int> res;
		for (auto &x : s) res.push_back(x);
		return res;
	}
};

void path(vector<vector<int>> &answer, vector<int> nodes) {
	if (nodes.size() == 1) return;
	for (int i = 1; i < (int)nodes.size(); i++) {
		answer[nodes[i - 1]][nodes[i]] = 1;
		answer[nodes[i]][nodes[i - 1]] = 1;
	}
}

void cycle(vector<vector<int>> &answer, vector<int> nodes) {
	if (nodes.size() == 1) return;
	path(answer, nodes);
	answer[nodes.back()][nodes[0]] = 1;
	answer[nodes[0]][nodes.back()] = 1;

}
int construct(vector<std::vector<int>> p) {
	int n = p.size();
	vector<vector<int>> answer;
	answer.resize(n);
	for (int i = 0; i < n; i++) {
		answer[i].resize(n);
		for (int j = 0; j < n; j++) {
			answer[i][j] = 0;
		}
	}
	dsu d(n);
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (p[i][j] != p[j][i]) return 0;
			if (p[i][j] > 0) d.unite(i, j);
		}
	}
	vector<int> roots = d.all_roots();
	int roots_num = (int)roots.size();
	unordered_map<int, int> ind;
	for (int i = 0; i < roots_num; i++) {
		ind[roots[i]] = i;
	}
	vector<vector<int>> parts(roots_num);
	for (int i = 0; i < n; i++) {
		parts[ind[d.get(i)]].push_back(i);
	}
	for (int i = 0; i < roots_num; i++) {
		vector<int> &cur = parts[i];
		if (cur.size() == 2) return 0;
		int small_sz = (int)cur.size();
		for (int j = 0; j < small_sz; j++) {
			for (int k = 0; k < small_sz; k++) {
				if (p[cur[j]][cur[k]] == 0) return 0;
			}
		}
		cycle(answer, cur);
	}
	build(answer);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Incorrect 1 ms 256 KB Answer gives possible 0 while actual possible 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Incorrect 1 ms 256 KB Answer gives possible 0 while actual possible 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 10 ms 1280 KB Output is correct
9 Correct 247 ms 22136 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 12 ms 1152 KB Output is correct
13 Correct 248 ms 22136 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 5 ms 768 KB Output is correct
17 Correct 115 ms 12156 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 64 ms 5880 KB Output is correct
22 Correct 240 ms 22136 KB Output is correct
23 Correct 254 ms 22136 KB Output is correct
24 Correct 246 ms 22188 KB Output is correct
25 Correct 105 ms 12380 KB Output is correct
26 Runtime error 123 ms 24568 KB Execution killed with signal 11
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Incorrect 1 ms 256 KB Too many ways to get from 1 to 4, should be 1 found no less than 2
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Incorrect 1 ms 256 KB Answer gives possible 0 while actual possible 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Incorrect 1 ms 256 KB Answer gives possible 0 while actual possible 1
3 Halted 0 ms 0 KB -