답안 #313750

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
313750 2020-10-16T22:22:36 Z Jasiekstrz 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
278 ms 30328 KB
#include<bits/stdc++.h>
#include "supertrees.h"
#define fi first
#define se second
using namespace std;
vector<int> e1[1010];
vector<int> e2[1010];
vector<int> sp[1010];
int g[1010];
bool vis1[1010];
bool vis2[1010];
vector<vector<int>> ans;
vector<vector<int>> p2;
int construct(vector<vector<int>> p)
{
	int n=p.size(),m,i,j;
	ans=vector<vector<int>>(n);
	for(i=0;i<n;i++)
		ans[i]=vector<int>(n);
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			ans[i][j]=0;
			if(p[i][j]==1)
				e1[i].push_back(j);
			if(p[i][j]==3 || p[i][j]!=p[j][i] || p[i][i]!=1)
				return 0;
		}
	}
	for(i=0,j=0;i<n;i++)
	{
		if(vis1[i])
			continue;
		for(auto v:e1[i])
		{
			if(vis1[v])
				return 0;
			vis1[v]=true;
			g[v]=j;
			sp[j].push_back(v);
		}
		for(auto v1:sp[j])
		{
			if(e1[v1].size()!=sp[j].size())
				return 0;
			for(auto v2:sp[j])
			{
				if(p[v1][v2]!=1)
					return 0;
			}
		}
		for(size_t it=1;it<sp[j].size();it++)
			ans[sp[j][it-1]][sp[j][it]]=ans[sp[j][it]][sp[j][it-1]]=1;
		j++;
	}
	m=j;
	p2=vector<vector<int>>(m);
	for(i=0;i<m;i++)
		p2[i]=vector<int>(m);
	for(i=0;i<m;i++)
	{
		for(j=0;j<m;j++)
			p2[i][j]=0;
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			if(p[i][j]==2)
				p2[g[i]][g[j]]=1;
		}
	}
	for(i=0;i<m;i++)
	{
		for(j=0;j<m;j++)
		{
			if(i==j)
				p2[i][j]=1;
			if(p2[i][j]==1)
				e2[i].push_back(j);
		}
	}
	for(i=0;i<m;i++)
	{
		if(vis2[i])
			continue;
		vector<int> tmp;
		for(auto v:e2[i])
		{
			if(vis2[v])
				return 0;
			vis2[v]=true;
			tmp.push_back(v);
		}
		for(auto v1:tmp)
		{
			for(auto vv1:sp[v1])
			{
				int xd=0;
				for(j=0;j<n;j++)
					xd+=(p[vv1][j]==2);
				for(auto v2:tmp)
				{
					if(v1==v2)
						continue;
					for(auto vv2:sp[v2])
					{
						xd--;
						if(p[vv1][vv2]!=2)
							return 0;
					}
				}
				if(xd!=0)
					return 0;
			}
		}
		for(size_t it=1;it<tmp.size();it++)
			ans[sp[tmp[it-1]][0]][sp[tmp[it]][0]]=ans[sp[tmp[it]][0]][sp[tmp[it-1]][0]]=1;
		if(tmp.size()>1)
			ans[sp[tmp.back()][0]][sp[tmp[0]][0]]=ans[sp[tmp[0]][0]][sp[tmp.back()][0]]=1;
		if(tmp.size()==2)
			return 0;
	}
	build(ans);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 1536 KB Output is correct
7 Correct 263 ms 26232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 1536 KB Output is correct
7 Correct 263 ms 26232 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 12 ms 1408 KB Output is correct
13 Correct 252 ms 26232 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 6 ms 1024 KB Output is correct
17 Correct 125 ms 14756 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 63 ms 6008 KB Output is correct
21 Correct 249 ms 22776 KB Output is correct
22 Correct 242 ms 22904 KB Output is correct
23 Correct 258 ms 24184 KB Output is correct
24 Correct 253 ms 25848 KB Output is correct
25 Correct 115 ms 12792 KB Output is correct
26 Correct 106 ms 12280 KB Output is correct
27 Correct 260 ms 25248 KB Output is correct
28 Correct 251 ms 25916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 11 ms 1408 KB Output is correct
9 Correct 251 ms 26232 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 12 ms 1664 KB Output is correct
13 Correct 278 ms 30328 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 6 ms 1152 KB Output is correct
17 Correct 148 ms 18680 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 64 ms 7032 KB Output is correct
22 Correct 265 ms 26744 KB Output is correct
23 Correct 260 ms 26360 KB Output is correct
24 Correct 276 ms 29304 KB Output is correct
25 Correct 120 ms 16248 KB Output is correct
26 Correct 126 ms 16804 KB Output is correct
27 Correct 252 ms 26276 KB Output is correct
28 Correct 272 ms 28280 KB Output is correct
29 Correct 119 ms 16284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 62 ms 6008 KB Output is correct
5 Correct 248 ms 22648 KB Output is correct
6 Correct 250 ms 22812 KB Output is correct
7 Correct 257 ms 24312 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 64 ms 6904 KB Output is correct
10 Correct 277 ms 26652 KB Output is correct
11 Correct 256 ms 26192 KB Output is correct
12 Correct 276 ms 29176 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 63 ms 6776 KB Output is correct
17 Correct 260 ms 26744 KB Output is correct
18 Correct 254 ms 23800 KB Output is correct
19 Correct 253 ms 23928 KB Output is correct
20 Correct 251 ms 26144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 1536 KB Output is correct
7 Correct 263 ms 26232 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 12 ms 1408 KB Output is correct
13 Correct 252 ms 26232 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 6 ms 1024 KB Output is correct
17 Correct 125 ms 14756 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 63 ms 6008 KB Output is correct
21 Correct 249 ms 22776 KB Output is correct
22 Correct 242 ms 22904 KB Output is correct
23 Correct 258 ms 24184 KB Output is correct
24 Correct 253 ms 25848 KB Output is correct
25 Correct 115 ms 12792 KB Output is correct
26 Correct 106 ms 12280 KB Output is correct
27 Correct 260 ms 25248 KB Output is correct
28 Correct 251 ms 25916 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 512 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 0 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 11 ms 1408 KB Output is correct
37 Correct 251 ms 26232 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 12 ms 1664 KB Output is correct
41 Correct 278 ms 30328 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 0 ms 384 KB Output is correct
44 Correct 6 ms 1152 KB Output is correct
45 Correct 148 ms 18680 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 64 ms 7032 KB Output is correct
50 Correct 265 ms 26744 KB Output is correct
51 Correct 260 ms 26360 KB Output is correct
52 Correct 276 ms 29304 KB Output is correct
53 Correct 120 ms 16248 KB Output is correct
54 Correct 126 ms 16804 KB Output is correct
55 Correct 252 ms 26276 KB Output is correct
56 Correct 272 ms 28280 KB Output is correct
57 Correct 119 ms 16284 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 0 ms 384 KB Output is correct
60 Correct 6 ms 896 KB Output is correct
61 Correct 143 ms 14328 KB Output is correct
62 Correct 1 ms 384 KB Output is correct
63 Correct 0 ms 384 KB Output is correct
64 Correct 1 ms 384 KB Output is correct
65 Correct 65 ms 6776 KB Output is correct
66 Correct 128 ms 16888 KB Output is correct
67 Correct 108 ms 12280 KB Output is correct
68 Correct 112 ms 13688 KB Output is correct
69 Correct 117 ms 16120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 1536 KB Output is correct
7 Correct 263 ms 26232 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 12 ms 1408 KB Output is correct
13 Correct 252 ms 26232 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 6 ms 1024 KB Output is correct
17 Correct 125 ms 14756 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 63 ms 6008 KB Output is correct
21 Correct 249 ms 22776 KB Output is correct
22 Correct 242 ms 22904 KB Output is correct
23 Correct 258 ms 24184 KB Output is correct
24 Correct 253 ms 25848 KB Output is correct
25 Correct 115 ms 12792 KB Output is correct
26 Correct 106 ms 12280 KB Output is correct
27 Correct 260 ms 25248 KB Output is correct
28 Correct 251 ms 25916 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 512 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 0 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 11 ms 1408 KB Output is correct
37 Correct 251 ms 26232 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 12 ms 1664 KB Output is correct
41 Correct 278 ms 30328 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 0 ms 384 KB Output is correct
44 Correct 6 ms 1152 KB Output is correct
45 Correct 148 ms 18680 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 64 ms 7032 KB Output is correct
50 Correct 265 ms 26744 KB Output is correct
51 Correct 260 ms 26360 KB Output is correct
52 Correct 276 ms 29304 KB Output is correct
53 Correct 120 ms 16248 KB Output is correct
54 Correct 126 ms 16804 KB Output is correct
55 Correct 252 ms 26276 KB Output is correct
56 Correct 272 ms 28280 KB Output is correct
57 Correct 119 ms 16284 KB Output is correct
58 Correct 0 ms 384 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 62 ms 6008 KB Output is correct
62 Correct 248 ms 22648 KB Output is correct
63 Correct 250 ms 22812 KB Output is correct
64 Correct 257 ms 24312 KB Output is correct
65 Correct 1 ms 384 KB Output is correct
66 Correct 64 ms 6904 KB Output is correct
67 Correct 277 ms 26652 KB Output is correct
68 Correct 256 ms 26192 KB Output is correct
69 Correct 276 ms 29176 KB Output is correct
70 Correct 1 ms 384 KB Output is correct
71 Correct 1 ms 384 KB Output is correct
72 Correct 1 ms 384 KB Output is correct
73 Correct 63 ms 6776 KB Output is correct
74 Correct 260 ms 26744 KB Output is correct
75 Correct 254 ms 23800 KB Output is correct
76 Correct 253 ms 23928 KB Output is correct
77 Correct 251 ms 26144 KB Output is correct
78 Correct 1 ms 384 KB Output is correct
79 Correct 0 ms 384 KB Output is correct
80 Correct 6 ms 896 KB Output is correct
81 Correct 143 ms 14328 KB Output is correct
82 Correct 1 ms 384 KB Output is correct
83 Correct 0 ms 384 KB Output is correct
84 Correct 1 ms 384 KB Output is correct
85 Correct 65 ms 6776 KB Output is correct
86 Correct 128 ms 16888 KB Output is correct
87 Correct 108 ms 12280 KB Output is correct
88 Correct 112 ms 13688 KB Output is correct
89 Correct 117 ms 16120 KB Output is correct
90 Correct 0 ms 384 KB Output is correct
91 Correct 1 ms 384 KB Output is correct
92 Correct 5 ms 896 KB Output is correct
93 Correct 115 ms 12188 KB Output is correct
94 Correct 1 ms 384 KB Output is correct
95 Correct 1 ms 384 KB Output is correct
96 Correct 1 ms 384 KB Output is correct
97 Correct 30 ms 3348 KB Output is correct
98 Correct 118 ms 12280 KB Output is correct
99 Correct 108 ms 12188 KB Output is correct
100 Correct 100 ms 12280 KB Output is correct
101 Correct 102 ms 12280 KB Output is correct
102 Correct 112 ms 12280 KB Output is correct
103 Correct 115 ms 12320 KB Output is correct
104 Correct 111 ms 12280 KB Output is correct
105 Correct 110 ms 12280 KB Output is correct