답안 #985775

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
985775 2024-05-18T19:04:14 Z Zbyszek99 슈퍼트리 잇기 (IOI20_supertrees) C++17
56 / 100
209 ms 31468 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,akttree)
	{
		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 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 7 ms 1880 KB Output is correct
7 Correct 178 ms 31468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 7 ms 1880 KB Output is correct
7 Correct 178 ms 31468 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 488 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 7 ms 1624 KB Output is correct
13 Correct 160 ms 27460 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 4 ms 1372 KB Output is correct
17 Correct 88 ms 20120 KB Output is correct
18 Correct 1 ms 756 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 41 ms 7416 KB Output is correct
21 Correct 162 ms 27940 KB Output is correct
22 Correct 165 ms 27728 KB Output is correct
23 Correct 174 ms 29428 KB Output is correct
24 Correct 181 ms 27476 KB Output is correct
25 Correct 74 ms 18044 KB Output is correct
26 Correct 76 ms 17464 KB Output is correct
27 Correct 187 ms 30532 KB Output is correct
28 Correct 157 ms 27472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 484 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 7 ms 1628 KB Output is correct
9 Correct 159 ms 27592 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1624 KB Output is correct
13 Correct 174 ms 27344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Incorrect 8 ms 1660 KB Answer gives possible 1 while actual possible 0
17 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 348 KB Output is correct
4 Correct 41 ms 7516 KB Output is correct
5 Correct 209 ms 27972 KB Output is correct
6 Correct 176 ms 27416 KB Output is correct
7 Correct 189 ms 30028 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 44 ms 7340 KB Output is correct
10 Correct 172 ms 27448 KB Output is correct
11 Correct 162 ms 27592 KB Output is correct
12 Correct 186 ms 27356 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 41 ms 7408 KB Output is correct
17 Correct 162 ms 27472 KB Output is correct
18 Correct 166 ms 27584 KB Output is correct
19 Correct 162 ms 27600 KB Output is correct
20 Correct 168 ms 27840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 7 ms 1880 KB Output is correct
7 Correct 178 ms 31468 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 488 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 7 ms 1624 KB Output is correct
13 Correct 160 ms 27460 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 4 ms 1372 KB Output is correct
17 Correct 88 ms 20120 KB Output is correct
18 Correct 1 ms 756 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 41 ms 7416 KB Output is correct
21 Correct 162 ms 27940 KB Output is correct
22 Correct 165 ms 27728 KB Output is correct
23 Correct 174 ms 29428 KB Output is correct
24 Correct 181 ms 27476 KB Output is correct
25 Correct 74 ms 18044 KB Output is correct
26 Correct 76 ms 17464 KB Output is correct
27 Correct 187 ms 30532 KB Output is correct
28 Correct 157 ms 27472 KB Output is correct
29 Correct 1 ms 484 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 7 ms 1628 KB Output is correct
37 Correct 159 ms 27592 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 7 ms 1624 KB Output is correct
41 Correct 174 ms 27344 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Incorrect 8 ms 1660 KB Answer gives possible 1 while actual possible 0
45 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 7 ms 1880 KB Output is correct
7 Correct 178 ms 31468 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 488 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 7 ms 1624 KB Output is correct
13 Correct 160 ms 27460 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 4 ms 1372 KB Output is correct
17 Correct 88 ms 20120 KB Output is correct
18 Correct 1 ms 756 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 41 ms 7416 KB Output is correct
21 Correct 162 ms 27940 KB Output is correct
22 Correct 165 ms 27728 KB Output is correct
23 Correct 174 ms 29428 KB Output is correct
24 Correct 181 ms 27476 KB Output is correct
25 Correct 74 ms 18044 KB Output is correct
26 Correct 76 ms 17464 KB Output is correct
27 Correct 187 ms 30532 KB Output is correct
28 Correct 157 ms 27472 KB Output is correct
29 Correct 1 ms 484 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 7 ms 1628 KB Output is correct
37 Correct 159 ms 27592 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 7 ms 1624 KB Output is correct
41 Correct 174 ms 27344 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Incorrect 8 ms 1660 KB Answer gives possible 1 while actual possible 0
45 Halted 0 ms 0 KB -