답안 #1078773

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1078773 2024-08-28T06:04:32 Z Faisal_Saqib 슈퍼트리 잇기 (IOI20_supertrees) C++17
21 / 100
192 ms 30040 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int N=1e3;
int reach[N][N],tree_case[N][N];
int par[N];
void init(int n)
{
	for(int i=0;i<n;i++)
		par[i]=i;
}
int get(int x)
{
	if(par[x]==x)return x;
	return par[x]=get(par[x]);
}
bool merge(int x,int y)
{
	x=get(x);
	y=get(y);
	if(x==y)return 0;
	par[y]=x;
	return 1;
}
vector<int> ma[N];
int head;
void dfs(int x)
{
	reach[head][x]=1;
	for(auto y:ma[x])
		if(!reach[head][y])
			dfs(y);
}
int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	init(n);
	bool two=0;
	for(int i=0;i<n;i++)
	{
		if(p[i][i]!=1)
			return 0;
		for(int j=0;j<n;j++)
		{
			two|=(p[i][j]==2);
			tree_case[i][j]=reach[i][j]=0;
		}
	}
	if(two)
	{
		for(int i=0;i<n;i++)
		{
			for(int j=i+1;j<n;j++)
			{
				if(p[i][j]==2)
				{
					merge(i,j);
				}
			}
		}
		for(int i=0;i<n;i++)
		{
			if(get(i)==i)
			{
				vector<int> component;
				for(int j=0;j<n;j++)
				{
					if(get(j)==i)
					{
						component.push_back(j);
					}
				}
				if(component.size()==2)
					return 0;
				component.push_back(component[0]);
				for(int i=1;i<component.size();i++)
				{
					tree_case[component[i-1]][component[i]]=1;
					tree_case[component[i]][component[i-1]]=1;
				}
			}
		}
	}
	else
	{		
		for(int i=0;i<n;i++)
		{
			for(int j=i+1;j<n;j++)
			{
				if(p[i][j]==1)
				{
					tree_case[i][j]=tree_case[j][i]=merge(i,j);
				}
			}
		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{	
			if(tree_case[i][j])
			{
				ma[i].push_back(j);
				ma[j].push_back(i);
			}
		}
	}
	vector<vector<int>> answer(n,vector<int>(n,0));
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			answer[i][j]=tree_case[i][j];
			reach[i][j]=0;
		}
		head=i;
		dfs(i);
		for(int j=0;j<n;j++)
		{
			p[i][j]-=(p[i][j]==2);// make 2 to 1
			if(reach[i][j]!=p[i][j])
			{
				return 0;
			}
		}
	}
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:75:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |     for(int i=1;i<component.size();i++)
      |                 ~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 6 ms 2908 KB Output is correct
7 Correct 127 ms 30040 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 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 6 ms 2908 KB Output is correct
7 Correct 127 ms 30040 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 388 KB Output is correct
12 Correct 6 ms 2908 KB Output is correct
13 Correct 121 ms 30000 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 2396 KB Output is correct
17 Correct 74 ms 20008 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 33 ms 9748 KB Output is correct
21 Correct 128 ms 30008 KB Output is correct
22 Correct 121 ms 30020 KB Output is correct
23 Correct 135 ms 30036 KB Output is correct
24 Correct 125 ms 29992 KB Output is correct
25 Correct 59 ms 20048 KB Output is correct
26 Correct 52 ms 20024 KB Output is correct
27 Correct 126 ms 30012 KB Output is correct
28 Correct 192 ms 30008 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 0 ms 348 KB Output is correct
5 Correct 0 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 5 ms 2908 KB Output is correct
9 Correct 119 ms 30036 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 6 ms 2908 KB Output is correct
13 Correct 125 ms 30008 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 2396 KB Output is correct
17 Correct 81 ms 20020 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Incorrect 0 ms 348 KB b[4][4] is not 0
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 31 ms 9664 KB Output is correct
5 Correct 122 ms 30012 KB Output is correct
6 Correct 124 ms 30032 KB Output is correct
7 Correct 171 ms 29988 KB Output is correct
8 Incorrect 0 ms 348 KB b[4][4] is not 0
9 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 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 6 ms 2908 KB Output is correct
7 Correct 127 ms 30040 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 388 KB Output is correct
12 Correct 6 ms 2908 KB Output is correct
13 Correct 121 ms 30000 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 2396 KB Output is correct
17 Correct 74 ms 20008 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 33 ms 9748 KB Output is correct
21 Correct 128 ms 30008 KB Output is correct
22 Correct 121 ms 30020 KB Output is correct
23 Correct 135 ms 30036 KB Output is correct
24 Correct 125 ms 29992 KB Output is correct
25 Correct 59 ms 20048 KB Output is correct
26 Correct 52 ms 20024 KB Output is correct
27 Correct 126 ms 30012 KB Output is correct
28 Correct 192 ms 30008 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 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 5 ms 2908 KB Output is correct
37 Correct 119 ms 30036 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 6 ms 2908 KB Output is correct
41 Correct 125 ms 30008 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 2396 KB Output is correct
45 Correct 81 ms 20020 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Incorrect 0 ms 348 KB b[4][4] is not 0
49 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 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 6 ms 2908 KB Output is correct
7 Correct 127 ms 30040 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 388 KB Output is correct
12 Correct 6 ms 2908 KB Output is correct
13 Correct 121 ms 30000 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 2396 KB Output is correct
17 Correct 74 ms 20008 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 33 ms 9748 KB Output is correct
21 Correct 128 ms 30008 KB Output is correct
22 Correct 121 ms 30020 KB Output is correct
23 Correct 135 ms 30036 KB Output is correct
24 Correct 125 ms 29992 KB Output is correct
25 Correct 59 ms 20048 KB Output is correct
26 Correct 52 ms 20024 KB Output is correct
27 Correct 126 ms 30012 KB Output is correct
28 Correct 192 ms 30008 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 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 5 ms 2908 KB Output is correct
37 Correct 119 ms 30036 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 6 ms 2908 KB Output is correct
41 Correct 125 ms 30008 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 2396 KB Output is correct
45 Correct 81 ms 20020 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Incorrect 0 ms 348 KB b[4][4] is not 0
49 Halted 0 ms 0 KB -