Submission #771513

# Submission time Handle Problem Language Result Execution time Memory
771513 2023-07-03T05:35:07 Z khshg Connecting Supertrees (IOI20_supertrees) C++14
0 / 100
1 ms 212 KB
#include"supertrees.h"
#include<bits/stdc++.h>
using namespace std;

int N;
vector<vector<int>> P, ans, D;
vector<int> par;

int parent(int x) {
	return (par[x] == x ? x : par[x] = parent(par[x]));
}

int unite(int x, int y) {
	x = parent(x);
	y = parent(y);
	if(x == y) return 1;
	if((int)D[x].size() < (int)D[y].size()) swap(x, y);
	for(auto& u : D[x]) for(auto& v : D[y]) {
		if(!P[u][v]) return 0;
	}
	for(auto& u : D[y]) D[x].emplace_back(u);
	par[y] = x;
	return 1;
}

int construct(vector<vector<int>> _p) {
	swap(P, _p);
	N = (int)P.size();
	D.resize(N);
	par.resize(N); iota(begin(par), end(par), 0);
	for(int i = 0; i < N; ++i) D[i].push_back(i);
	for(int i = 0; i < N; ++i) {
		for(int j = i + 1; j < N; ++j) {
			if(P[i][j]) {
				if(!unite(i, j)) {
					return 0;
				}
			}
		}
	}
	vector<int> comps;
	{
		set<int> s;
		for(int i = 0; i < N; ++i) {
			s.insert(parent(i));
		}
		comps = vector<int>(begin(s), end(s));
	}
	ans = vector<vector<int>>(N, vector<int>(N, 0));
	for(auto& u : comps) {
		if(D[u].size() == 1) continue;
		ans[D[u][0]][D[u].back()] = 1;
		ans[D[u].back()][D[u][0]] = 1;
		for(int i = 1; i < (int)D[u].size(); ++i) {
			ans[D[u][i]][D[u][i - 1]] = 1;
			ans[D[u][i - 1]][D[u][i]] = 1;
		}
	}
	build(ans);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Too many ways to get from 0 to 2, should be 1 found no less than 2
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Too many ways to get from 0 to 2, should be 1 found no less than 2
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 1 ms 212 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 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 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 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Too many ways to get from 0 to 2, should be 1 found no less than 2
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Too many ways to get from 0 to 2, should be 1 found no less than 2
4 Halted 0 ms 0 KB -