| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 580360 | joelau | Connecting Supertrees (IOI20_supertrees) | C++14 | 184 ms | 24008 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
int N,ufds[1005], rnk[1005];
vector<int> lst[1005];
int findSet(int i) {
	return ufds[i] == i ? i : ufds[i] = findSet(ufds[i]);
}
void unionSet(int i, int j) {
	int a = findSet(i), b = findSet(j);
	if (a == b) return;
	if (rnk[a] < rnk[b]) ufds[a] = b;
	if (rnk[a] > rnk[b]) ufds[b] = a;
	if (rnk[a] == rnk[b]) ufds[a] = b, rnk[b]++;
}
int construct(vector<vector<int>> p) {
	N = p.size();
	for (int i = 0; i < N; ++i) if (p[i][i] != 1) return 0;
	for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) if (p[i][j] != p[j][i]) return 0;
	for (int i = 0; i < N; ++i) ufds[i] = i, rnk[i] = 1;
	for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) if (p[i][j] == 2) unionSet(i,j);
	for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) if (i != j) {
		if (p[i][j] == 2 && findSet(i) != findSet(j)) return 0;
		if (p[i][j] == 0 && findSet(i) == findSet(j)) return 0;
	}
	vector< vector<int> > ans(N, vector<int>(N,0));
	for (int i = 0; i < N; ++i) lst[findSet(i)].push_back(i);
	for (int i = 0; i < N; ++i) {
		if (lst[i].size() == 2) return 0;
		if (lst[i].size() == 3) {
			for (int j = 1; j < lst[i].size(); ++j) ans[lst[i][j-1]][lst[i][j]] = ans[lst[i][j]][lst[i][j-1]] = 1;
			ans[lst[i].front()][lst[i].back()] = ans[lst[i].back()][lst[i].front()] = 1;
		}
	}
	build(ans);
	return 1;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
