Submission #369734

# Submission time Handle Problem Language Result Execution time Memory
369734 2021-02-22T10:23:04 Z MilosMilutinovic Connecting Supertrees (IOI20_supertrees) C++14
0 / 100
1 ms 384 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;

#define pb push_back

const int mxN=1e3;

int r[mxN], sz[mxN];
vector<int> g[mxN];

int find(int x) {
	return x^r[x]?r[x]=find(r[x]):x;
}

void join(int x, int y) {
	x=find(x),y=find(y);
	if(sz[x]>sz[y])
		swap(x,y);
	r[x]=y;
	sz[y]+=sz[x];
}

int construct(vector<vector<int>> p) {
	int n=(int)p.size();
	for(int i=0; i<n; ++i)
		for(int j=0; j<n; ++j)
			if(p[i][j]==3)
				return 0;
	iota(r, r+n, 0);
	memset(sz, 1, sizeof(sz));
	for(int i=0; i<n; ++i)
		for(int j=i+1; j<n; ++j)
			if(p[i][j]==1)
				join(i,j);
	vector<vector<int>> ans(n, vector<int>(n));
	vector<int> roots;
	for(int i=0; i<n; ++i) {
		int j=find(i);
		if(j==i)
			roots.pb(i);
		else
			ans[i][j]=ans[j][i]=1;
	}
	for(int i=0; i<n; ++i)
		for(int j=0; j<n; ++j)
			if(p[i][j]!=p[find(i)][find(j)])
				return 0;
	iota(r, r+n, 0);
	memset(sz, 1, sizeof(sz));
	for(int i:roots)
		for(int j:roots)
			if(p[i][j]==3)
				join(i,j);
	for(int i:roots)
		if(sz[find(i)]>=2)
			g[find(i)].pb(i);
	for(int i=0; i<n; ++i) {
		if(!g[i].empty()&&(int)g[i].size()<=2)
			return 0;
		if(g[i].empty())
			continue;
		for(int x:g[i]) {
			for(int y:g[i]) {
				if(x!=y&&p[x][y]!=2)
					return 0;
			}
		}
		for(int j=1;j<(int)g[i].size();j++) {
			int x=g[i][j],y=g[i][j-1];
			ans[x][y]=ans[y][x]=1;
		}
		int x=g[i][0],y=g[i].back();
		ans[x][y]=ans[y][x]=1;
	}
	build(ans);
	return 1;
}

# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Answer gives possible 0 while actual possible 1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Answer gives possible 0 while actual possible 1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Answer gives possible 0 while actual possible 1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Answer gives possible 0 while actual possible 1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Answer gives possible 0 while actual possible 1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Answer gives possible 0 while actual possible 1
2 Halted 0 ms 0 KB -