#include <bits/stdc++.h>
#include "supertrees.h"
#define inf 1000000007
#define mod 1000000007
#define rnd() rand_num()
#define bigrnd() dis(rand_num)
//#pragma GCC optimize("Ofast","inline","-ffast-math")
//#pragma GCC target("avx,sse2,sse3,sse4,mmx")
//#define int long long
using namespace std;
unsigned sed=std::chrono::system_clock::now().time_since_epoch().count();
mt19937 rand_num(sed);
uniform_int_distribution<long long> dis(0,inf);
template <typename T> void read(T &x){
x=0;char ch=getchar();int fh=1;
while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
x*=fh;
}
template <typename T> void write(T x) {
if (x<0) x=-x,putchar('-');
if (x>9) write(x/10);
putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
write(x);
puts("");
}
int n;
int fa[1005];
int fa1[1005];
int g[1005][1005];
int fnd(int x)
{
if(fa[x]!=x) fa[x]=fnd(fa[x]);
return fa[x];
}
int fnd1(int x)
{
if(fa1[x]!=x) fa1[x]=fnd1(fa1[x]);
return fa1[x];
}
int construct(vector<vector<int>> p)
{
n=p.size();
for(int i=0;i<n;++i)
fa[i]=i;
for(int i=0;i<n;++i)
for(int j=0;j<n;++j)
if(p[i][j]==3)
return 0;
else if(p[i][j])
fa[fnd(i)]=fnd(j);
for(int i=0;i<n;++i)
for(int j=0;j<n;++j)
if(!p[i][j]&&fnd(i)==fnd(j))
return 0;
for(int i=0;i<n;++i)
fa1[i]=i;
for(int i=0;i<n;++i)
for(int j=0;j<n;++j)
if(p[i][j]==1)
fa1[fnd1(i)]=fnd1(j);
for(int i=0;i<n;++i)
for(int j=0;j<n;++j)
if(p[i][j]==2&&fnd1(i)==fnd1(j))
return 0;
for(int i=0;i<n;++i)
if(fnd(i)==i)
{
vector<int> vec;
for(int j=0;j<n;++j)
if(fnd(j)==i)
vec.push_back(fnd1(j));
sort(vec.begin(),vec.end());
vec.erase(unique(vec.begin(),vec.end()),vec.end());
bool flag=false;
for(int j=0;j<vec.size();++j)
for(int k=j+1;k<vec.size();++k)
if(p[vec[j]][vec[k]]==2)
flag=true;
if(flag&&vec.size()<3) return 0;
if(flag)
{
for(int j=0;j+1<vec.size();++j)
g[vec[j]][vec[j+1]]=g[vec[j+1]][vec[j]]=1;
g[vec[0]][vec[vec.size()-1]]=g[vec[vec.size()-1]][vec[0]]=1;
}
for(int j=0;j<n;++j)
if(fnd(j)==i&&fnd1(j)!=j)
g[j][fnd1(j)]=g[fnd1(j)][j]=1;
}
vector<vector<int>> ans;
for(int i=0;i<n;++i)
{
vector<int> tmp;
for(int j=0;j<n;++j)
tmp.push_back(g[i][j]);
ans.push_back(tmp);
}
build(ans);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:78:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for(int j=0;j<vec.size();++j)
| ~^~~~~~~~~~~
supertrees.cpp:79:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for(int k=j+1;k<vec.size();++k)
| ~^~~~~~~~~~~
supertrees.cpp:85:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | for(int j=0;j+1<vec.size();++j)
| ~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
11 ms |
1996 KB |
Output is correct |
7 |
Correct |
250 ms |
26004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
11 ms |
1996 KB |
Output is correct |
7 |
Correct |
250 ms |
26004 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
10 ms |
1112 KB |
Output is correct |
13 |
Correct |
254 ms |
22108 KB |
Output is correct |
14 |
Correct |
2 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
5 ms |
588 KB |
Output is correct |
17 |
Correct |
104 ms |
8092 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
60 ms |
7492 KB |
Output is correct |
21 |
Correct |
242 ms |
25992 KB |
Output is correct |
22 |
Correct |
268 ms |
25456 KB |
Output is correct |
23 |
Correct |
265 ms |
25908 KB |
Output is correct |
24 |
Correct |
231 ms |
22260 KB |
Output is correct |
25 |
Correct |
96 ms |
8088 KB |
Output is correct |
26 |
Correct |
92 ms |
8088 KB |
Output is correct |
27 |
Correct |
246 ms |
26004 KB |
Output is correct |
28 |
Correct |
238 ms |
22184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
11 ms |
1128 KB |
Output is correct |
9 |
Correct |
232 ms |
22064 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
13 ms |
1920 KB |
Output is correct |
13 |
Correct |
241 ms |
26008 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
5 ms |
592 KB |
Output is correct |
17 |
Correct |
105 ms |
8092 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 |
60 ms |
7612 KB |
Output is correct |
22 |
Correct |
272 ms |
26008 KB |
Output is correct |
23 |
Correct |
253 ms |
25892 KB |
Output is correct |
24 |
Correct |
275 ms |
25892 KB |
Output is correct |
25 |
Correct |
108 ms |
8212 KB |
Output is correct |
26 |
Correct |
94 ms |
8080 KB |
Output is correct |
27 |
Correct |
228 ms |
25868 KB |
Output is correct |
28 |
Correct |
246 ms |
25992 KB |
Output is correct |
29 |
Correct |
101 ms |
8260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
61 ms |
7588 KB |
Output is correct |
5 |
Correct |
230 ms |
26044 KB |
Output is correct |
6 |
Correct |
244 ms |
25432 KB |
Output is correct |
7 |
Correct |
242 ms |
25992 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
66 ms |
7584 KB |
Output is correct |
10 |
Correct |
237 ms |
26004 KB |
Output is correct |
11 |
Correct |
233 ms |
25920 KB |
Output is correct |
12 |
Correct |
247 ms |
26004 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
58 ms |
8056 KB |
Output is correct |
17 |
Correct |
232 ms |
27912 KB |
Output is correct |
18 |
Correct |
246 ms |
27644 KB |
Output is correct |
19 |
Correct |
237 ms |
27516 KB |
Output is correct |
20 |
Correct |
232 ms |
24248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
11 ms |
1996 KB |
Output is correct |
7 |
Correct |
250 ms |
26004 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
10 ms |
1112 KB |
Output is correct |
13 |
Correct |
254 ms |
22108 KB |
Output is correct |
14 |
Correct |
2 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
5 ms |
588 KB |
Output is correct |
17 |
Correct |
104 ms |
8092 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
60 ms |
7492 KB |
Output is correct |
21 |
Correct |
242 ms |
25992 KB |
Output is correct |
22 |
Correct |
268 ms |
25456 KB |
Output is correct |
23 |
Correct |
265 ms |
25908 KB |
Output is correct |
24 |
Correct |
231 ms |
22260 KB |
Output is correct |
25 |
Correct |
96 ms |
8088 KB |
Output is correct |
26 |
Correct |
92 ms |
8088 KB |
Output is correct |
27 |
Correct |
246 ms |
26004 KB |
Output is correct |
28 |
Correct |
238 ms |
22184 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 |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
0 ms |
204 KB |
Output is correct |
36 |
Correct |
11 ms |
1128 KB |
Output is correct |
37 |
Correct |
232 ms |
22064 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
13 ms |
1920 KB |
Output is correct |
41 |
Correct |
241 ms |
26008 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
1 ms |
204 KB |
Output is correct |
44 |
Correct |
5 ms |
592 KB |
Output is correct |
45 |
Correct |
105 ms |
8092 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 |
60 ms |
7612 KB |
Output is correct |
50 |
Correct |
272 ms |
26008 KB |
Output is correct |
51 |
Correct |
253 ms |
25892 KB |
Output is correct |
52 |
Correct |
275 ms |
25892 KB |
Output is correct |
53 |
Correct |
108 ms |
8212 KB |
Output is correct |
54 |
Correct |
94 ms |
8080 KB |
Output is correct |
55 |
Correct |
228 ms |
25868 KB |
Output is correct |
56 |
Correct |
246 ms |
25992 KB |
Output is correct |
57 |
Correct |
101 ms |
8260 KB |
Output is correct |
58 |
Correct |
1 ms |
204 KB |
Output is correct |
59 |
Correct |
1 ms |
204 KB |
Output is correct |
60 |
Correct |
5 ms |
588 KB |
Output is correct |
61 |
Correct |
103 ms |
8088 KB |
Output is correct |
62 |
Correct |
1 ms |
204 KB |
Output is correct |
63 |
Correct |
1 ms |
332 KB |
Output is correct |
64 |
Correct |
1 ms |
332 KB |
Output is correct |
65 |
Correct |
73 ms |
8004 KB |
Output is correct |
66 |
Correct |
94 ms |
10120 KB |
Output is correct |
67 |
Correct |
93 ms |
10108 KB |
Output is correct |
68 |
Correct |
119 ms |
10044 KB |
Output is correct |
69 |
Correct |
99 ms |
10140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
11 ms |
1996 KB |
Output is correct |
7 |
Correct |
250 ms |
26004 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
10 ms |
1112 KB |
Output is correct |
13 |
Correct |
254 ms |
22108 KB |
Output is correct |
14 |
Correct |
2 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
5 ms |
588 KB |
Output is correct |
17 |
Correct |
104 ms |
8092 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
60 ms |
7492 KB |
Output is correct |
21 |
Correct |
242 ms |
25992 KB |
Output is correct |
22 |
Correct |
268 ms |
25456 KB |
Output is correct |
23 |
Correct |
265 ms |
25908 KB |
Output is correct |
24 |
Correct |
231 ms |
22260 KB |
Output is correct |
25 |
Correct |
96 ms |
8088 KB |
Output is correct |
26 |
Correct |
92 ms |
8088 KB |
Output is correct |
27 |
Correct |
246 ms |
26004 KB |
Output is correct |
28 |
Correct |
238 ms |
22184 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 |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
0 ms |
204 KB |
Output is correct |
36 |
Correct |
11 ms |
1128 KB |
Output is correct |
37 |
Correct |
232 ms |
22064 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
13 ms |
1920 KB |
Output is correct |
41 |
Correct |
241 ms |
26008 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
1 ms |
204 KB |
Output is correct |
44 |
Correct |
5 ms |
592 KB |
Output is correct |
45 |
Correct |
105 ms |
8092 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 |
60 ms |
7612 KB |
Output is correct |
50 |
Correct |
272 ms |
26008 KB |
Output is correct |
51 |
Correct |
253 ms |
25892 KB |
Output is correct |
52 |
Correct |
275 ms |
25892 KB |
Output is correct |
53 |
Correct |
108 ms |
8212 KB |
Output is correct |
54 |
Correct |
94 ms |
8080 KB |
Output is correct |
55 |
Correct |
228 ms |
25868 KB |
Output is correct |
56 |
Correct |
246 ms |
25992 KB |
Output is correct |
57 |
Correct |
101 ms |
8260 KB |
Output is correct |
58 |
Correct |
1 ms |
204 KB |
Output is correct |
59 |
Correct |
1 ms |
204 KB |
Output is correct |
60 |
Correct |
1 ms |
332 KB |
Output is correct |
61 |
Correct |
61 ms |
7588 KB |
Output is correct |
62 |
Correct |
230 ms |
26044 KB |
Output is correct |
63 |
Correct |
244 ms |
25432 KB |
Output is correct |
64 |
Correct |
242 ms |
25992 KB |
Output is correct |
65 |
Correct |
1 ms |
204 KB |
Output is correct |
66 |
Correct |
66 ms |
7584 KB |
Output is correct |
67 |
Correct |
237 ms |
26004 KB |
Output is correct |
68 |
Correct |
233 ms |
25920 KB |
Output is correct |
69 |
Correct |
247 ms |
26004 KB |
Output is correct |
70 |
Correct |
1 ms |
204 KB |
Output is correct |
71 |
Correct |
1 ms |
332 KB |
Output is correct |
72 |
Correct |
1 ms |
332 KB |
Output is correct |
73 |
Correct |
58 ms |
8056 KB |
Output is correct |
74 |
Correct |
232 ms |
27912 KB |
Output is correct |
75 |
Correct |
246 ms |
27644 KB |
Output is correct |
76 |
Correct |
237 ms |
27516 KB |
Output is correct |
77 |
Correct |
232 ms |
24248 KB |
Output is correct |
78 |
Correct |
1 ms |
204 KB |
Output is correct |
79 |
Correct |
1 ms |
204 KB |
Output is correct |
80 |
Correct |
5 ms |
588 KB |
Output is correct |
81 |
Correct |
103 ms |
8088 KB |
Output is correct |
82 |
Correct |
1 ms |
204 KB |
Output is correct |
83 |
Correct |
1 ms |
332 KB |
Output is correct |
84 |
Correct |
1 ms |
332 KB |
Output is correct |
85 |
Correct |
73 ms |
8004 KB |
Output is correct |
86 |
Correct |
94 ms |
10120 KB |
Output is correct |
87 |
Correct |
93 ms |
10108 KB |
Output is correct |
88 |
Correct |
119 ms |
10044 KB |
Output is correct |
89 |
Correct |
99 ms |
10140 KB |
Output is correct |
90 |
Correct |
1 ms |
204 KB |
Output is correct |
91 |
Correct |
1 ms |
204 KB |
Output is correct |
92 |
Correct |
7 ms |
672 KB |
Output is correct |
93 |
Correct |
97 ms |
10108 KB |
Output is correct |
94 |
Correct |
1 ms |
204 KB |
Output is correct |
95 |
Correct |
1 ms |
204 KB |
Output is correct |
96 |
Correct |
1 ms |
204 KB |
Output is correct |
97 |
Correct |
23 ms |
2680 KB |
Output is correct |
98 |
Correct |
92 ms |
10104 KB |
Output is correct |
99 |
Correct |
90 ms |
10124 KB |
Output is correct |
100 |
Correct |
94 ms |
10116 KB |
Output is correct |
101 |
Correct |
89 ms |
10112 KB |
Output is correct |
102 |
Correct |
89 ms |
10108 KB |
Output is correct |
103 |
Correct |
90 ms |
10052 KB |
Output is correct |
104 |
Correct |
93 ms |
10120 KB |
Output is correct |
105 |
Correct |
97 ms |
10036 KB |
Output is correct |