#include "supertrees.h"
#include <bits/stdc++.h>
#define SIZE 1001
using namespace std;
int root[SIZE], a[SIZE];
vector<vector<int> > con;
vector<vector<vector<int> > > lin;
int Find(int x)
{
if (x==root[x]) return x;
return root[x]=Find(root[x]);
}
void Union(int x, int y)
{
if (Find(x)==Find(y)) return;
root[root[x]]=root[y];
}
int construct(vector<vector<int> > p)
{
int N=p.size(), M;
vector<vector<int> > ret(N);
for (int i=0; i<N; i++) {
ret[i].resize(N);
root[i]=i, a[i]=-1;
}
for (int i=0; i<N; i++) for (int j=0; j<N; j++) if (i!=j) {
if (p[i][j]==3) return 0;
if (p[i][j]!=0) Union(i, j);
}
for (int i=0; i<N; i++) {
if (a[Find(i)]==-1) {
a[root[i]]=con.size();
vector<int> v;
v.push_back(i);
con.push_back(v);
}
else con[a[root[i]]].push_back(i);
}
M=con.size();
lin.resize(M);
for (int i=0; i<M; i++) for (int j : con[i]) for (int k : con[i]) if (p[j][k]==0) return 0;
for (int i=0; i<N; i++) root[i]=i, a[i]=-1;
for (int i=0; i<M; i++) {
for (int j : con[i]) for (int k : con[i]) if (j!=k && p[j][k]==1) Union(j, k);
for (int j : con[i]) {
if (a[Find(j)]==-1) {
a[root[j]]=lin[i].size();
vector<int> v;
v.push_back(j);
lin[i].push_back(v);
}
else lin[i][a[root[j]]].push_back(j);
}
if (lin[i].size()==2) return 0;
for (int j=0; j<lin[i].size(); j++) for (int k : lin[i][j]) for (int l : lin[i][j]) if (p[k][l]==2) return 0;
for (int j=0; j<lin[i].size(); j++) for (int k=0; k<lin[i][j].size(); k++) {
if (k!=0) ret[lin[i][j][k]][lin[i][j][k-1]]=1;
if (k!=lin[i][j].size()-1) ret[lin[i][j][k]][lin[i][j][k+1]]=1;
}
for (int j=0; j<lin[i].size()-1; j++) ret[lin[i][j][0]][lin[i][j+1][0]]=ret[lin[i][j+1][0]][lin[i][j][0]]=1;
if (lin[i].size()>1) {
ret[lin[i][lin[i].size()-1][0]][lin[i][0][0]]=1;
ret[lin[i][0][0]][lin[i][lin[i].size()-1][0]]=1;
}
}
build(ret);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:55:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for (int j=0; j<lin[i].size(); j++) for (int k : lin[i][j]) for (int l : lin[i][j]) if (p[k][l]==2) return 0;
| ~^~~~~~~~~~~~~~
supertrees.cpp:56:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for (int j=0; j<lin[i].size(); j++) for (int k=0; k<lin[i][j].size(); k++) {
| ~^~~~~~~~~~~~~~
supertrees.cpp:56:60: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for (int j=0; j<lin[i].size(); j++) for (int k=0; k<lin[i][j].size(); k++) {
| ~^~~~~~~~~~~~~~~~~
supertrees.cpp:58:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | if (k!=lin[i][j].size()-1) ret[lin[i][j][k]][lin[i][j][k+1]]=1;
| ~^~~~~~~~~~~~~~~~~~~~
supertrees.cpp:60:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for (int j=0; j<lin[i].size()-1; j++) ret[lin[i][j][0]][lin[i][j+1][0]]=ret[lin[i][j+1][0]][lin[i][j][0]]=1;
| ~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
284 KB |
Output is correct |
3 |
Correct |
0 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
11 ms |
1228 KB |
Output is correct |
7 |
Correct |
239 ms |
23968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
284 KB |
Output is correct |
3 |
Correct |
0 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
11 ms |
1228 KB |
Output is correct |
7 |
Correct |
239 ms |
23968 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
292 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
10 ms |
1200 KB |
Output is correct |
13 |
Correct |
227 ms |
24032 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
292 KB |
Output is correct |
16 |
Correct |
5 ms |
792 KB |
Output is correct |
17 |
Correct |
122 ms |
14064 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
59 ms |
6256 KB |
Output is correct |
21 |
Correct |
230 ms |
23936 KB |
Output is correct |
22 |
Correct |
255 ms |
24132 KB |
Output is correct |
23 |
Correct |
265 ms |
23972 KB |
Output is correct |
24 |
Correct |
229 ms |
24120 KB |
Output is correct |
25 |
Correct |
99 ms |
14080 KB |
Output is correct |
26 |
Correct |
96 ms |
14072 KB |
Output is correct |
27 |
Correct |
250 ms |
24008 KB |
Output is correct |
28 |
Correct |
238 ms |
24056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
10 ms |
1300 KB |
Output is correct |
9 |
Correct |
241 ms |
24048 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
10 ms |
1228 KB |
Output is correct |
13 |
Correct |
235 ms |
23964 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
5 ms |
820 KB |
Output is correct |
17 |
Correct |
110 ms |
14060 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
59 ms |
6216 KB |
Output is correct |
22 |
Correct |
235 ms |
24004 KB |
Output is correct |
23 |
Correct |
239 ms |
24044 KB |
Output is correct |
24 |
Correct |
249 ms |
24004 KB |
Output is correct |
25 |
Correct |
113 ms |
14276 KB |
Output is correct |
26 |
Correct |
98 ms |
14060 KB |
Output is correct |
27 |
Correct |
233 ms |
23988 KB |
Output is correct |
28 |
Correct |
247 ms |
24064 KB |
Output is correct |
29 |
Correct |
92 ms |
14204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
58 ms |
6220 KB |
Output is correct |
5 |
Correct |
242 ms |
23916 KB |
Output is correct |
6 |
Correct |
225 ms |
24040 KB |
Output is correct |
7 |
Correct |
256 ms |
23996 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
67 ms |
6256 KB |
Output is correct |
10 |
Correct |
273 ms |
24060 KB |
Output is correct |
11 |
Correct |
241 ms |
24096 KB |
Output is correct |
12 |
Correct |
256 ms |
24096 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
292 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
58 ms |
6212 KB |
Output is correct |
17 |
Correct |
234 ms |
24060 KB |
Output is correct |
18 |
Correct |
242 ms |
24004 KB |
Output is correct |
19 |
Correct |
277 ms |
23988 KB |
Output is correct |
20 |
Correct |
250 ms |
24056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
284 KB |
Output is correct |
3 |
Correct |
0 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
11 ms |
1228 KB |
Output is correct |
7 |
Correct |
239 ms |
23968 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
292 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
10 ms |
1200 KB |
Output is correct |
13 |
Correct |
227 ms |
24032 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
292 KB |
Output is correct |
16 |
Correct |
5 ms |
792 KB |
Output is correct |
17 |
Correct |
122 ms |
14064 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
59 ms |
6256 KB |
Output is correct |
21 |
Correct |
230 ms |
23936 KB |
Output is correct |
22 |
Correct |
255 ms |
24132 KB |
Output is correct |
23 |
Correct |
265 ms |
23972 KB |
Output is correct |
24 |
Correct |
229 ms |
24120 KB |
Output is correct |
25 |
Correct |
99 ms |
14080 KB |
Output is correct |
26 |
Correct |
96 ms |
14072 KB |
Output is correct |
27 |
Correct |
250 ms |
24008 KB |
Output is correct |
28 |
Correct |
238 ms |
24056 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
296 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
10 ms |
1300 KB |
Output is correct |
37 |
Correct |
241 ms |
24048 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
10 ms |
1228 KB |
Output is correct |
41 |
Correct |
235 ms |
23964 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
0 ms |
204 KB |
Output is correct |
44 |
Correct |
5 ms |
820 KB |
Output is correct |
45 |
Correct |
110 ms |
14060 KB |
Output is correct |
46 |
Correct |
1 ms |
204 KB |
Output is correct |
47 |
Correct |
1 ms |
204 KB |
Output is correct |
48 |
Correct |
1 ms |
204 KB |
Output is correct |
49 |
Correct |
59 ms |
6216 KB |
Output is correct |
50 |
Correct |
235 ms |
24004 KB |
Output is correct |
51 |
Correct |
239 ms |
24044 KB |
Output is correct |
52 |
Correct |
249 ms |
24004 KB |
Output is correct |
53 |
Correct |
113 ms |
14276 KB |
Output is correct |
54 |
Correct |
98 ms |
14060 KB |
Output is correct |
55 |
Correct |
233 ms |
23988 KB |
Output is correct |
56 |
Correct |
247 ms |
24064 KB |
Output is correct |
57 |
Correct |
92 ms |
14204 KB |
Output is correct |
58 |
Correct |
1 ms |
204 KB |
Output is correct |
59 |
Correct |
1 ms |
292 KB |
Output is correct |
60 |
Correct |
6 ms |
824 KB |
Output is correct |
61 |
Correct |
109 ms |
14080 KB |
Output is correct |
62 |
Correct |
1 ms |
204 KB |
Output is correct |
63 |
Correct |
1 ms |
296 KB |
Output is correct |
64 |
Correct |
1 ms |
204 KB |
Output is correct |
65 |
Correct |
64 ms |
6192 KB |
Output is correct |
66 |
Correct |
105 ms |
14060 KB |
Output is correct |
67 |
Correct |
113 ms |
14072 KB |
Output is correct |
68 |
Correct |
94 ms |
14060 KB |
Output is correct |
69 |
Correct |
133 ms |
14068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
284 KB |
Output is correct |
3 |
Correct |
0 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
11 ms |
1228 KB |
Output is correct |
7 |
Correct |
239 ms |
23968 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
292 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
10 ms |
1200 KB |
Output is correct |
13 |
Correct |
227 ms |
24032 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
292 KB |
Output is correct |
16 |
Correct |
5 ms |
792 KB |
Output is correct |
17 |
Correct |
122 ms |
14064 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
59 ms |
6256 KB |
Output is correct |
21 |
Correct |
230 ms |
23936 KB |
Output is correct |
22 |
Correct |
255 ms |
24132 KB |
Output is correct |
23 |
Correct |
265 ms |
23972 KB |
Output is correct |
24 |
Correct |
229 ms |
24120 KB |
Output is correct |
25 |
Correct |
99 ms |
14080 KB |
Output is correct |
26 |
Correct |
96 ms |
14072 KB |
Output is correct |
27 |
Correct |
250 ms |
24008 KB |
Output is correct |
28 |
Correct |
238 ms |
24056 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
296 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
10 ms |
1300 KB |
Output is correct |
37 |
Correct |
241 ms |
24048 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
10 ms |
1228 KB |
Output is correct |
41 |
Correct |
235 ms |
23964 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
0 ms |
204 KB |
Output is correct |
44 |
Correct |
5 ms |
820 KB |
Output is correct |
45 |
Correct |
110 ms |
14060 KB |
Output is correct |
46 |
Correct |
1 ms |
204 KB |
Output is correct |
47 |
Correct |
1 ms |
204 KB |
Output is correct |
48 |
Correct |
1 ms |
204 KB |
Output is correct |
49 |
Correct |
59 ms |
6216 KB |
Output is correct |
50 |
Correct |
235 ms |
24004 KB |
Output is correct |
51 |
Correct |
239 ms |
24044 KB |
Output is correct |
52 |
Correct |
249 ms |
24004 KB |
Output is correct |
53 |
Correct |
113 ms |
14276 KB |
Output is correct |
54 |
Correct |
98 ms |
14060 KB |
Output is correct |
55 |
Correct |
233 ms |
23988 KB |
Output is correct |
56 |
Correct |
247 ms |
24064 KB |
Output is correct |
57 |
Correct |
92 ms |
14204 KB |
Output is correct |
58 |
Correct |
0 ms |
204 KB |
Output is correct |
59 |
Correct |
1 ms |
204 KB |
Output is correct |
60 |
Correct |
1 ms |
204 KB |
Output is correct |
61 |
Correct |
58 ms |
6220 KB |
Output is correct |
62 |
Correct |
242 ms |
23916 KB |
Output is correct |
63 |
Correct |
225 ms |
24040 KB |
Output is correct |
64 |
Correct |
256 ms |
23996 KB |
Output is correct |
65 |
Correct |
1 ms |
204 KB |
Output is correct |
66 |
Correct |
67 ms |
6256 KB |
Output is correct |
67 |
Correct |
273 ms |
24060 KB |
Output is correct |
68 |
Correct |
241 ms |
24096 KB |
Output is correct |
69 |
Correct |
256 ms |
24096 KB |
Output is correct |
70 |
Correct |
1 ms |
204 KB |
Output is correct |
71 |
Correct |
1 ms |
292 KB |
Output is correct |
72 |
Correct |
1 ms |
204 KB |
Output is correct |
73 |
Correct |
58 ms |
6212 KB |
Output is correct |
74 |
Correct |
234 ms |
24060 KB |
Output is correct |
75 |
Correct |
242 ms |
24004 KB |
Output is correct |
76 |
Correct |
277 ms |
23988 KB |
Output is correct |
77 |
Correct |
250 ms |
24056 KB |
Output is correct |
78 |
Correct |
1 ms |
204 KB |
Output is correct |
79 |
Correct |
1 ms |
292 KB |
Output is correct |
80 |
Correct |
6 ms |
824 KB |
Output is correct |
81 |
Correct |
109 ms |
14080 KB |
Output is correct |
82 |
Correct |
1 ms |
204 KB |
Output is correct |
83 |
Correct |
1 ms |
296 KB |
Output is correct |
84 |
Correct |
1 ms |
204 KB |
Output is correct |
85 |
Correct |
64 ms |
6192 KB |
Output is correct |
86 |
Correct |
105 ms |
14060 KB |
Output is correct |
87 |
Correct |
113 ms |
14072 KB |
Output is correct |
88 |
Correct |
94 ms |
14060 KB |
Output is correct |
89 |
Correct |
133 ms |
14068 KB |
Output is correct |
90 |
Correct |
1 ms |
204 KB |
Output is correct |
91 |
Correct |
1 ms |
204 KB |
Output is correct |
92 |
Correct |
5 ms |
844 KB |
Output is correct |
93 |
Correct |
105 ms |
14060 KB |
Output is correct |
94 |
Correct |
0 ms |
204 KB |
Output is correct |
95 |
Correct |
0 ms |
204 KB |
Output is correct |
96 |
Correct |
1 ms |
204 KB |
Output is correct |
97 |
Correct |
35 ms |
3700 KB |
Output is correct |
98 |
Correct |
94 ms |
14080 KB |
Output is correct |
99 |
Correct |
104 ms |
14060 KB |
Output is correct |
100 |
Correct |
97 ms |
14064 KB |
Output is correct |
101 |
Correct |
93 ms |
14076 KB |
Output is correct |
102 |
Correct |
96 ms |
14020 KB |
Output is correct |
103 |
Correct |
99 ms |
14020 KB |
Output is correct |
104 |
Correct |
96 ms |
14072 KB |
Output is correct |
105 |
Correct |
102 ms |
14064 KB |
Output is correct |