답안 #985776

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
985776 2024-05-18T19:07:37 Z Zbyszek99 슈퍼트리 잇기 (IOI20_supertrees) C++17
56 / 100
190 ms 30156 KB
#include "supertrees.h"
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;

vector<vector<int>> ans;
int n;
vector<int> graf1[1000];
bitset<1000> odw;
vector<vector<int>> p;
int tree[1000];
int pop_tree[1000];
int rep_t[1000];
int rep[1000];
int typ_pol[1000];
vector<int> cycle[1000];
int akttree = 0;

int find_(int v)
{
	if(rep[v] == v) return v;
	rep[v] = find_(rep[v]); return rep[v];
}

int union_(int a, int b, int a2, int b2)
{
	rep[find_(b)] = find_(a);
	if(typ_pol[find_(b)] == 0 || typ_pol[find_(a)] == 0)
	{
		typ_pol[find_(b)] = max(typ_pol[find_(b)],typ_pol[find_(a)]);
		typ_pol[find_(a)] = max(typ_pol[find_(b)],typ_pol[find_(a)]);
	}
	if(typ_pol[find_(b)] == 0)
	{
		typ_pol[find_(b)] = p[a2][b2];
		typ_pol[find_(a)] = p[a2][b2];
	}
	//cout << typ_pol[find_(a)] << " " << typ_pol[find_(b)] << " " << a2 << " " << b2 <<  " typy\n"; 
	if(typ_pol[find_(a)] != typ_pol[find_(b)] || p[a2][b2] != typ_pol[find_(a)])
	{
		return -1;
	}
	return 0;
}

void dfs(int v)
{
	odw[v] = 1;
 	tree[v] = akttree;
	rep_t[akttree] = v;
	for(auto& it: graf1[v]) if(odw[it] == 0) dfs(it); 
}

int construct(vector<vector<int>> p2) {
	p = p2;
	n = (int)p.size();
	ans.resize(n);
	rep(i,n)
	{
		pop_tree[i] = -1;
		rep(j,n)
		ans[i].push_back(0);
		rep[i] = i;
	}
	rep(i,n) rep(j,n)
	{
		if(p[i][j] == 3) return 0;
		if(p[i][j] == 1 && i != j) graf1[i].push_back(j); 
	}
	rep(i,n)
	{
		if(odw[i] == 0) 
		{
			dfs(i);
			akttree++;
		}
	}
	rep(i,n) rep(j,n)
	{
		if(tree[i] == tree[j] && p[i][j] != 1) 
		{
			//cout << " zle tree\n";
			return 0;
		}
	}
	rep(i,n) rep(j,n)
	{
		if(p[i][j] >= 2 && tree[i] != tree[j]) 
		{
		//	cout << i << " " << j << " " << tree[i] << " " << tree[j] << " union\n";
			if(union_(tree[i],tree[j],i,j) == -1)
			{
				//cout << tree[i] << " " << tree[j] << " " << i << " " << j << " zle union\n"; 
				return 0;
			}
		}
	}
	rep(i,n)
	{
		if(pop_tree[tree[i]] != -1)
		{
			ans[i][pop_tree[tree[i]]] = 1;
			ans[pop_tree[tree[i]]][i] = 1;
		}
		pop_tree[tree[i]] = i;
	}
	rep(i,akttree)
	{
		//cout << find_(i) << " " << rep_t[i]<< " find\n";
		cycle[find_(i)].push_back(rep_t[i]);
	}
	rep(i,n)
	{
		int ile = (int)cycle[i].size();
		
		if(ile == 0) continue;
		if(ile == 1) continue;
		//cout << ile << " " << i << " cycle\n";
		int typ = p[cycle[i][0]][cycle[i][1]];
		if(typ == 0)
		{
			//cout <<  " typ 0\n";
			return 0;
		}
		if(typ == 2)
		{
			if(ile < 3) 
			{
				//cout << " ile < 3\n";
				return 0;
			}
			for(int j = 0; j < ile-1; j++)
			{
				ans[cycle[i][j]][cycle[i][j+1]] = 1;
				ans[cycle[i][j+1]][cycle[i][j]] = 1;
			}
			ans[cycle[i][0]][cycle[i][ile-1]] = 1;
			ans[cycle[i][ile-1]][cycle[i][0]] = 1;
		}	
	}
	build(ans);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1628 KB Output is correct
7 Correct 175 ms 30156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1628 KB Output is correct
7 Correct 175 ms 30156 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1368 KB Output is correct
13 Correct 170 ms 26192 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 4 ms 1164 KB Output is correct
17 Correct 93 ms 18760 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 43 ms 6836 KB Output is correct
21 Correct 172 ms 26764 KB Output is correct
22 Correct 176 ms 26496 KB Output is correct
23 Correct 184 ms 28240 KB Output is correct
24 Correct 174 ms 26324 KB Output is correct
25 Correct 81 ms 16716 KB Output is correct
26 Correct 82 ms 16216 KB Output is correct
27 Correct 188 ms 29400 KB Output is correct
28 Correct 186 ms 26192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 8 ms 1372 KB Output is correct
9 Correct 170 ms 26188 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 8 ms 1456 KB Output is correct
13 Correct 184 ms 26172 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Incorrect 9 ms 1416 KB Answer gives possible 1 while actual possible 0
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 44 ms 6820 KB Output is correct
5 Correct 171 ms 26704 KB Output is correct
6 Correct 169 ms 26176 KB Output is correct
7 Correct 180 ms 28248 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 43 ms 6964 KB Output is correct
10 Correct 173 ms 26068 KB Output is correct
11 Correct 190 ms 26176 KB Output is correct
12 Correct 188 ms 26172 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 49 ms 6840 KB Output is correct
17 Correct 176 ms 26316 KB Output is correct
18 Correct 172 ms 26188 KB Output is correct
19 Correct 171 ms 26196 KB Output is correct
20 Correct 172 ms 26196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1628 KB Output is correct
7 Correct 175 ms 30156 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1368 KB Output is correct
13 Correct 170 ms 26192 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 4 ms 1164 KB Output is correct
17 Correct 93 ms 18760 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 43 ms 6836 KB Output is correct
21 Correct 172 ms 26764 KB Output is correct
22 Correct 176 ms 26496 KB Output is correct
23 Correct 184 ms 28240 KB Output is correct
24 Correct 174 ms 26324 KB Output is correct
25 Correct 81 ms 16716 KB Output is correct
26 Correct 82 ms 16216 KB Output is correct
27 Correct 188 ms 29400 KB Output is correct
28 Correct 186 ms 26192 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 8 ms 1372 KB Output is correct
37 Correct 170 ms 26188 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 8 ms 1456 KB Output is correct
41 Correct 184 ms 26172 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Incorrect 9 ms 1416 KB Answer gives possible 1 while actual possible 0
45 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1628 KB Output is correct
7 Correct 175 ms 30156 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1368 KB Output is correct
13 Correct 170 ms 26192 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 4 ms 1164 KB Output is correct
17 Correct 93 ms 18760 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 43 ms 6836 KB Output is correct
21 Correct 172 ms 26764 KB Output is correct
22 Correct 176 ms 26496 KB Output is correct
23 Correct 184 ms 28240 KB Output is correct
24 Correct 174 ms 26324 KB Output is correct
25 Correct 81 ms 16716 KB Output is correct
26 Correct 82 ms 16216 KB Output is correct
27 Correct 188 ms 29400 KB Output is correct
28 Correct 186 ms 26192 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 8 ms 1372 KB Output is correct
37 Correct 170 ms 26188 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 8 ms 1456 KB Output is correct
41 Correct 184 ms 26172 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Incorrect 9 ms 1416 KB Answer gives possible 1 while actual possible 0
45 Halted 0 ms 0 KB -