답안 #591820

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
591820 2022-07-08T00:44:53 Z penguinhacker 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
216 ms 31952 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;

const int mxN=1000;
int n, who[mxN], cnt;
vector<int> adj[mxN], cur_component;
vector<vector<int>> p, cmp, ans, edge2;
bool vis[mxN];

void dfs0(int i) {
	who[i]=cnt;
	for (int j=0; j<n; ++j)
		if (i!=j&&who[j]==-1&&p[i][j])
			dfs0(j);
}

bool check0() {
	memset(who, -1, 4*n);
	cnt=0;
	for (int i=0; i<n; ++i)
		if (who[i]==-1)
			dfs0(i), ++cnt;
	for (int i=0; i<n; ++i)
		for (int j=i+1; j<n; ++j)
			if (who[i]==who[j]&&p[i][j]==0)
				return 0;
	return 1;
}

void dfs1(int i) {
	who[i]=cnt;
	for (int j=0; j<n; ++j)
		if (i!=j&&who[j]==-1&&p[i][j]==1)
			dfs1(j);
}

bool check1() {
	memset(who, -1, 4*n);
	for (int i=0; i<n; ++i)
		if (who[i]==-1)
			cnt=i, dfs1(i);
	for (int i=0; i<n; ++i)
		for (int j=i+1; j<n; ++j)
			if (who[i]==who[j]&&p[i][j]!=1)
				return 0;
	for (int j=0; j<n; ++j) {
		int last=-1;
		for (int i=0; i<n; ++i)
			if (who[i]==j) {
				if (last!=-1)
					ans[last][i]=ans[i][last]=1;
				last=i;
			}
	}
	return 1;
}

void dfs2(int i) {
	vis[i]=1;
	cur_component.push_back(i);
	for (int j=0; j<n; ++j)
		if (who[j]==j&&!vis[j]&&i!=j&&p[i][j]==2)
			dfs2(j);
}

bool check2() {
	for (int i=0; i<n; ++i)
		for (int j=0; j<n; ++j)
			if (p[i][j]!=1&&p[i][j]!=p[who[i]][who[j]])
				return 0;
	memset(vis, 0, n);
	for (int i=0; i<n; ++i) {
		if (i!=who[i]||vis[i])
			continue;
		cur_component.clear();
		dfs2(i);
		//cout << i << endl;
		if (cur_component.size()==1)
			continue;
		if (cur_component.size()==2)
			return 0;
		for (int j=0; j<cur_component.size(); ++j) {
			int a=cur_component[j], b=cur_component[(j+1)%cur_component.size()];
			ans[a][b]=ans[b][a]=1;
		}
	}
	return 1;
}

int construct(vector<vector<int>> _p) {
	p=_p, n=p.size();
	for (int i=0; i<n; ++i)
		for (int j=i+1; j<n; ++j)
			if (p[i][j]==3)
				return 0;
	ans=edge2=vector<vector<int>>(n, vector<int>(n));
	if (!check0()||!check1()||!check2())
		return 0;
	build(ans);
	return 1;
}

Compilation message

supertrees.cpp: In function 'bool check2()':
supertrees.cpp:83:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |   for (int j=0; j<cur_component.size(); ++j) {
      |                 ~^~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/string.h:495,
                 from /usr/include/c++/10/cstring:42,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:48,
                 from supertrees.cpp:2:
In function 'void* memset(void*, int, size_t)',
    inlined from 'bool check2()' at supertrees.cpp:72:8:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:71:33: warning: 'void* __builtin___memset_chk(void*, int, long unsigned int, long unsigned int)' specified size between 18446744071562067968 and 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
   71 |   return __builtin___memset_chk (__dest, __ch, __len, __bos0 (__dest));
      |          ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1620 KB Output is correct
7 Correct 175 ms 31912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1620 KB Output is correct
7 Correct 175 ms 31912 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 9 ms 1620 KB Output is correct
13 Correct 185 ms 31812 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 4 ms 1108 KB Output is correct
17 Correct 82 ms 22032 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 46 ms 8208 KB Output is correct
21 Correct 178 ms 31820 KB Output is correct
22 Correct 183 ms 31896 KB Output is correct
23 Correct 184 ms 31932 KB Output is correct
24 Correct 168 ms 31892 KB Output is correct
25 Correct 85 ms 21956 KB Output is correct
26 Correct 75 ms 21952 KB Output is correct
27 Correct 216 ms 31888 KB Output is correct
28 Correct 186 ms 31820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 10 ms 1492 KB Output is correct
9 Correct 188 ms 29864 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 8 ms 1492 KB Output is correct
13 Correct 194 ms 29984 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 1108 KB Output is correct
17 Correct 84 ms 20116 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 49 ms 7740 KB Output is correct
22 Correct 178 ms 29864 KB Output is correct
23 Correct 182 ms 29964 KB Output is correct
24 Correct 180 ms 29900 KB Output is correct
25 Correct 72 ms 20000 KB Output is correct
26 Correct 75 ms 20044 KB Output is correct
27 Correct 187 ms 29960 KB Output is correct
28 Correct 179 ms 29936 KB Output is correct
29 Correct 73 ms 19984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 44 ms 8176 KB Output is correct
5 Correct 172 ms 31884 KB Output is correct
6 Correct 174 ms 31896 KB Output is correct
7 Correct 177 ms 31840 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 47 ms 8260 KB Output is correct
10 Correct 175 ms 31900 KB Output is correct
11 Correct 169 ms 31844 KB Output is correct
12 Correct 178 ms 31952 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 44 ms 8332 KB Output is correct
17 Correct 177 ms 31896 KB Output is correct
18 Correct 182 ms 31908 KB Output is correct
19 Correct 200 ms 31856 KB Output is correct
20 Correct 178 ms 31888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1620 KB Output is correct
7 Correct 175 ms 31912 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 9 ms 1620 KB Output is correct
13 Correct 185 ms 31812 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 4 ms 1108 KB Output is correct
17 Correct 82 ms 22032 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 46 ms 8208 KB Output is correct
21 Correct 178 ms 31820 KB Output is correct
22 Correct 183 ms 31896 KB Output is correct
23 Correct 184 ms 31932 KB Output is correct
24 Correct 168 ms 31892 KB Output is correct
25 Correct 85 ms 21956 KB Output is correct
26 Correct 75 ms 21952 KB Output is correct
27 Correct 216 ms 31888 KB Output is correct
28 Correct 186 ms 31820 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 10 ms 1492 KB Output is correct
37 Correct 188 ms 29864 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 8 ms 1492 KB Output is correct
41 Correct 194 ms 29984 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 3 ms 1108 KB Output is correct
45 Correct 84 ms 20116 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 49 ms 7740 KB Output is correct
50 Correct 178 ms 29864 KB Output is correct
51 Correct 182 ms 29964 KB Output is correct
52 Correct 180 ms 29900 KB Output is correct
53 Correct 72 ms 20000 KB Output is correct
54 Correct 75 ms 20044 KB Output is correct
55 Correct 187 ms 29960 KB Output is correct
56 Correct 179 ms 29936 KB Output is correct
57 Correct 73 ms 19984 KB Output is correct
58 Correct 1 ms 328 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 4 ms 1108 KB Output is correct
61 Correct 79 ms 22044 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 48 ms 8252 KB Output is correct
66 Correct 72 ms 22032 KB Output is correct
67 Correct 73 ms 22032 KB Output is correct
68 Correct 83 ms 22028 KB Output is correct
69 Correct 83 ms 21920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1620 KB Output is correct
7 Correct 175 ms 31912 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 9 ms 1620 KB Output is correct
13 Correct 185 ms 31812 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 4 ms 1108 KB Output is correct
17 Correct 82 ms 22032 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 46 ms 8208 KB Output is correct
21 Correct 178 ms 31820 KB Output is correct
22 Correct 183 ms 31896 KB Output is correct
23 Correct 184 ms 31932 KB Output is correct
24 Correct 168 ms 31892 KB Output is correct
25 Correct 85 ms 21956 KB Output is correct
26 Correct 75 ms 21952 KB Output is correct
27 Correct 216 ms 31888 KB Output is correct
28 Correct 186 ms 31820 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 10 ms 1492 KB Output is correct
37 Correct 188 ms 29864 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 8 ms 1492 KB Output is correct
41 Correct 194 ms 29984 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 3 ms 1108 KB Output is correct
45 Correct 84 ms 20116 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 49 ms 7740 KB Output is correct
50 Correct 178 ms 29864 KB Output is correct
51 Correct 182 ms 29964 KB Output is correct
52 Correct 180 ms 29900 KB Output is correct
53 Correct 72 ms 20000 KB Output is correct
54 Correct 75 ms 20044 KB Output is correct
55 Correct 187 ms 29960 KB Output is correct
56 Correct 179 ms 29936 KB Output is correct
57 Correct 73 ms 19984 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 44 ms 8176 KB Output is correct
62 Correct 172 ms 31884 KB Output is correct
63 Correct 174 ms 31896 KB Output is correct
64 Correct 177 ms 31840 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 47 ms 8260 KB Output is correct
67 Correct 175 ms 31900 KB Output is correct
68 Correct 169 ms 31844 KB Output is correct
69 Correct 178 ms 31952 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 1 ms 212 KB Output is correct
73 Correct 44 ms 8332 KB Output is correct
74 Correct 177 ms 31896 KB Output is correct
75 Correct 182 ms 31908 KB Output is correct
76 Correct 200 ms 31856 KB Output is correct
77 Correct 178 ms 31888 KB Output is correct
78 Correct 1 ms 328 KB Output is correct
79 Correct 1 ms 212 KB Output is correct
80 Correct 4 ms 1108 KB Output is correct
81 Correct 79 ms 22044 KB Output is correct
82 Correct 0 ms 212 KB Output is correct
83 Correct 1 ms 212 KB Output is correct
84 Correct 1 ms 212 KB Output is correct
85 Correct 48 ms 8252 KB Output is correct
86 Correct 72 ms 22032 KB Output is correct
87 Correct 73 ms 22032 KB Output is correct
88 Correct 83 ms 22028 KB Output is correct
89 Correct 83 ms 21920 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 1 ms 212 KB Output is correct
92 Correct 4 ms 852 KB Output is correct
93 Correct 82 ms 14096 KB Output is correct
94 Correct 1 ms 212 KB Output is correct
95 Correct 0 ms 328 KB Output is correct
96 Correct 1 ms 328 KB Output is correct
97 Correct 17 ms 3788 KB Output is correct
98 Correct 77 ms 14108 KB Output is correct
99 Correct 71 ms 14092 KB Output is correct
100 Correct 67 ms 14096 KB Output is correct
101 Correct 65 ms 14028 KB Output is correct
102 Correct 65 ms 14112 KB Output is correct
103 Correct 71 ms 14104 KB Output is correct
104 Correct 70 ms 14032 KB Output is correct
105 Correct 84 ms 14108 KB Output is correct