#include "supertrees.h"
#include <vector>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <string>
int t[1010];
bool e[1010],dc[1010];
int tata(int nod)
{
if(t[nod]==nod) return nod;
return t[nod]=tata(t[nod]);
}
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
std::vector<std::vector<int>> answer;
answer.resize(n);
for (int i = 0; i < n; i++) {
t[i]=i;
dc[i]=false;
e[i]=true;
answer[i].resize(n);
}
for(int i=0;i<n;++i)
{
for(int j=0;j<n;++j)
if(p[i][j]==1)
{
if(tata(i)!=tata(j))
{
answer[i][j]=answer[j][i]=1;
t[t[i]]=t[j];
}
}
}
for(int i=0;i<n;++i)
{
for(int j=0;j<n;++j)
if(p[i][j]==0)
{
if(tata(i)==tata(j))
return 0;
}
}
for(int i=0;i<n;++i)
if(e[i])
for(int j=i+1;j<n;++j)
{
if(e[j])
if(tata(i)==tata(j))
{
e[j]=false;
for(int q=0;q<n;++q)
if(p[i][q]!=p[j][q])
return 0;
}
}
int ciclu[1010];
for(int i=0;i<n;++i)
{
if(e[i]==true&&dc[i]==false)
{
ciclu[0]=1;
ciclu[1]=i;
for(int j=0;j<n;++j)
if(e[j]&&p[i][j]==2)
{
ciclu[++ciclu[0]]=j;
if(dc[j])
return 0;
}
if(ciclu[0]>2)
{
for(int ii=1;ii<=ciclu[0];++ii)
{
dc[ciclu[ii]]=true;
if(ii!=ciclu[0])
answer[ciclu[ii]][ciclu[ii+1]]=answer[ciclu[ii+1]][ciclu[ii]]=1;
for(int jj=ii+1;jj<=ciclu[0];++jj)
if(p[ciclu[ii]][ciclu[jj]]!=2)
return 0;
}
answer[ciclu[ciclu[0]]][ciclu[1]]=answer[ciclu[1]][ciclu[ciclu[0]]]=1;
}
else if(ciclu[0]==2)
return 0;
}
}
build(answer);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 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 |
8 ms |
1108 KB |
Output is correct |
7 |
Correct |
181 ms |
22028 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 |
0 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 |
8 ms |
1108 KB |
Output is correct |
7 |
Correct |
181 ms |
22028 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1176 KB |
Output is correct |
13 |
Correct |
249 ms |
22020 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
724 KB |
Output is correct |
17 |
Correct |
118 ms |
12028 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
49 ms |
5764 KB |
Output is correct |
21 |
Correct |
202 ms |
22012 KB |
Output is correct |
22 |
Correct |
191 ms |
22024 KB |
Output is correct |
23 |
Correct |
191 ms |
21968 KB |
Output is correct |
24 |
Correct |
201 ms |
22012 KB |
Output is correct |
25 |
Correct |
93 ms |
12028 KB |
Output is correct |
26 |
Correct |
88 ms |
12032 KB |
Output is correct |
27 |
Correct |
198 ms |
22016 KB |
Output is correct |
28 |
Correct |
189 ms |
22000 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 |
0 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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
11 ms |
1092 KB |
Output is correct |
9 |
Correct |
191 ms |
22020 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
11 ms |
1108 KB |
Output is correct |
13 |
Correct |
187 ms |
22024 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
724 KB |
Output is correct |
17 |
Correct |
104 ms |
12032 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
49 ms |
5708 KB |
Output is correct |
22 |
Correct |
202 ms |
23928 KB |
Output is correct |
23 |
Correct |
207 ms |
23912 KB |
Output is correct |
24 |
Correct |
223 ms |
23908 KB |
Output is correct |
25 |
Correct |
113 ms |
13988 KB |
Output is correct |
26 |
Incorrect |
209 ms |
23920 KB |
Answer gives possible 1 while actual possible 0 |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
48 ms |
5696 KB |
Output is correct |
5 |
Correct |
206 ms |
21980 KB |
Output is correct |
6 |
Correct |
202 ms |
22084 KB |
Output is correct |
7 |
Correct |
208 ms |
22008 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
54 ms |
5652 KB |
Output is correct |
10 |
Correct |
194 ms |
24136 KB |
Output is correct |
11 |
Correct |
197 ms |
24004 KB |
Output is correct |
12 |
Correct |
213 ms |
23984 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
288 KB |
Output is correct |
16 |
Correct |
50 ms |
6248 KB |
Output is correct |
17 |
Correct |
204 ms |
23924 KB |
Output is correct |
18 |
Correct |
212 ms |
23936 KB |
Output is correct |
19 |
Correct |
223 ms |
24176 KB |
Output is correct |
20 |
Correct |
212 ms |
23996 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 |
0 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 |
8 ms |
1108 KB |
Output is correct |
7 |
Correct |
181 ms |
22028 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1176 KB |
Output is correct |
13 |
Correct |
249 ms |
22020 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
724 KB |
Output is correct |
17 |
Correct |
118 ms |
12028 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
49 ms |
5764 KB |
Output is correct |
21 |
Correct |
202 ms |
22012 KB |
Output is correct |
22 |
Correct |
191 ms |
22024 KB |
Output is correct |
23 |
Correct |
191 ms |
21968 KB |
Output is correct |
24 |
Correct |
201 ms |
22012 KB |
Output is correct |
25 |
Correct |
93 ms |
12028 KB |
Output is correct |
26 |
Correct |
88 ms |
12032 KB |
Output is correct |
27 |
Correct |
198 ms |
22016 KB |
Output is correct |
28 |
Correct |
189 ms |
22000 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
11 ms |
1092 KB |
Output is correct |
37 |
Correct |
191 ms |
22020 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
11 ms |
1108 KB |
Output is correct |
41 |
Correct |
187 ms |
22024 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
5 ms |
724 KB |
Output is correct |
45 |
Correct |
104 ms |
12032 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
49 ms |
5708 KB |
Output is correct |
50 |
Correct |
202 ms |
23928 KB |
Output is correct |
51 |
Correct |
207 ms |
23912 KB |
Output is correct |
52 |
Correct |
223 ms |
23908 KB |
Output is correct |
53 |
Correct |
113 ms |
13988 KB |
Output is correct |
54 |
Incorrect |
209 ms |
23920 KB |
Answer gives possible 1 while actual possible 0 |
55 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 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 |
8 ms |
1108 KB |
Output is correct |
7 |
Correct |
181 ms |
22028 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1176 KB |
Output is correct |
13 |
Correct |
249 ms |
22020 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
724 KB |
Output is correct |
17 |
Correct |
118 ms |
12028 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
49 ms |
5764 KB |
Output is correct |
21 |
Correct |
202 ms |
22012 KB |
Output is correct |
22 |
Correct |
191 ms |
22024 KB |
Output is correct |
23 |
Correct |
191 ms |
21968 KB |
Output is correct |
24 |
Correct |
201 ms |
22012 KB |
Output is correct |
25 |
Correct |
93 ms |
12028 KB |
Output is correct |
26 |
Correct |
88 ms |
12032 KB |
Output is correct |
27 |
Correct |
198 ms |
22016 KB |
Output is correct |
28 |
Correct |
189 ms |
22000 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
11 ms |
1092 KB |
Output is correct |
37 |
Correct |
191 ms |
22020 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
11 ms |
1108 KB |
Output is correct |
41 |
Correct |
187 ms |
22024 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
5 ms |
724 KB |
Output is correct |
45 |
Correct |
104 ms |
12032 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
49 ms |
5708 KB |
Output is correct |
50 |
Correct |
202 ms |
23928 KB |
Output is correct |
51 |
Correct |
207 ms |
23912 KB |
Output is correct |
52 |
Correct |
223 ms |
23908 KB |
Output is correct |
53 |
Correct |
113 ms |
13988 KB |
Output is correct |
54 |
Incorrect |
209 ms |
23920 KB |
Answer gives possible 1 while actual possible 0 |
55 |
Halted |
0 ms |
0 KB |
- |