#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
long long n,dsu[2][1069];
vector<long long> vl[1069];
long long fd(long long xx,long long x)
{
if(dsu[xx][x]!=x)
{
dsu[xx][x]=fd(xx,dsu[xx][x]);
}
return dsu[xx][x];
}
int construct(vector<vector<int>> a)
{
long long i,j,ii,k,l,sz;
vector<int> v;
vector<vector<int>> sq;
n=a.size();
for(i=0;i<n;i++)
{
for(ii=0;ii<2;ii++)
{
dsu[ii][i]=i;
}
sq.push_back(v);
for(j=0;j<n;j++)
{
sq[i].push_back(0);
}
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i][j]==1&&fd(0,i)!=fd(0,j))
{
sq[i][j]=1;
sq[j][i]=1;
for(ii=0;ii<2;ii++)
{
dsu[ii][fd(ii,j)]=fd(ii,i);
}
}
}
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i][j]==2)
{
dsu[1][fd(1,j)]=fd(1,i);
}
}
}
for(i=0;i<n;i++)
{
if(fd(0,i)==i)
{
vl[fd(1,i)].push_back(i);
}
}
for(i=0;i<n;i++)
{
sz=vl[i].size();
if(sz==2)
{
return 0;
}
for(j=0;j<sz;j++)
{
k=vl[i][j];
if(j)
{
sq[k][l]=1;
sq[l][k]=1;
}
l=k;
}
if(sz>=3)
{
sq[l][vl[i][0]]=1;
sq[vl[i][0]][l]=1;
}
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if((!a[i][j]&&fd(1,i)==fd(1,j))||(a[i][j]==2&&fd(0,i)==fd(0,j))||a[i][j]==3)
{
return 0;
}
}
}
build(sq);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1372 KB |
Output is correct |
7 |
Correct |
149 ms |
24148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1372 KB |
Output is correct |
7 |
Correct |
149 ms |
24148 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1624 KB |
Output is correct |
13 |
Correct |
146 ms |
24104 KB |
Output is correct |
14 |
Correct |
1 ms |
356 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
872 KB |
Output is correct |
17 |
Correct |
73 ms |
14360 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
37 ms |
6376 KB |
Output is correct |
21 |
Correct |
168 ms |
24116 KB |
Output is correct |
22 |
Correct |
149 ms |
24232 KB |
Output is correct |
23 |
Correct |
151 ms |
24144 KB |
Output is correct |
24 |
Correct |
150 ms |
24148 KB |
Output is correct |
25 |
Correct |
61 ms |
14164 KB |
Output is correct |
26 |
Correct |
61 ms |
14164 KB |
Output is correct |
27 |
Correct |
159 ms |
24144 KB |
Output is correct |
28 |
Correct |
148 ms |
24228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
6 ms |
1624 KB |
Output is correct |
9 |
Correct |
155 ms |
24236 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1624 KB |
Output is correct |
13 |
Correct |
154 ms |
24148 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
107 ms |
14160 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
49 ms |
6420 KB |
Output is correct |
22 |
Correct |
150 ms |
24148 KB |
Output is correct |
23 |
Correct |
156 ms |
24060 KB |
Output is correct |
24 |
Correct |
156 ms |
24220 KB |
Output is correct |
25 |
Correct |
64 ms |
14168 KB |
Output is correct |
26 |
Correct |
65 ms |
14232 KB |
Output is correct |
27 |
Correct |
150 ms |
24148 KB |
Output is correct |
28 |
Correct |
156 ms |
24248 KB |
Output is correct |
29 |
Correct |
65 ms |
14164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
39 ms |
6276 KB |
Output is correct |
5 |
Correct |
152 ms |
24204 KB |
Output is correct |
6 |
Correct |
146 ms |
24120 KB |
Output is correct |
7 |
Correct |
151 ms |
24144 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
38 ms |
6248 KB |
Output is correct |
10 |
Correct |
156 ms |
24088 KB |
Output is correct |
11 |
Correct |
174 ms |
24124 KB |
Output is correct |
12 |
Correct |
153 ms |
24080 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
43 ms |
6244 KB |
Output is correct |
17 |
Correct |
163 ms |
24088 KB |
Output is correct |
18 |
Correct |
157 ms |
24148 KB |
Output is correct |
19 |
Correct |
158 ms |
24052 KB |
Output is correct |
20 |
Correct |
157 ms |
24212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1372 KB |
Output is correct |
7 |
Correct |
149 ms |
24148 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1624 KB |
Output is correct |
13 |
Correct |
146 ms |
24104 KB |
Output is correct |
14 |
Correct |
1 ms |
356 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
872 KB |
Output is correct |
17 |
Correct |
73 ms |
14360 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
37 ms |
6376 KB |
Output is correct |
21 |
Correct |
168 ms |
24116 KB |
Output is correct |
22 |
Correct |
149 ms |
24232 KB |
Output is correct |
23 |
Correct |
151 ms |
24144 KB |
Output is correct |
24 |
Correct |
150 ms |
24148 KB |
Output is correct |
25 |
Correct |
61 ms |
14164 KB |
Output is correct |
26 |
Correct |
61 ms |
14164 KB |
Output is correct |
27 |
Correct |
159 ms |
24144 KB |
Output is correct |
28 |
Correct |
148 ms |
24228 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
6 ms |
1624 KB |
Output is correct |
37 |
Correct |
155 ms |
24236 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
7 ms |
1624 KB |
Output is correct |
41 |
Correct |
154 ms |
24148 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
3 ms |
860 KB |
Output is correct |
45 |
Correct |
107 ms |
14160 KB |
Output is correct |
46 |
Correct |
1 ms |
344 KB |
Output is correct |
47 |
Correct |
0 ms |
344 KB |
Output is correct |
48 |
Correct |
1 ms |
348 KB |
Output is correct |
49 |
Correct |
49 ms |
6420 KB |
Output is correct |
50 |
Correct |
150 ms |
24148 KB |
Output is correct |
51 |
Correct |
156 ms |
24060 KB |
Output is correct |
52 |
Correct |
156 ms |
24220 KB |
Output is correct |
53 |
Correct |
64 ms |
14168 KB |
Output is correct |
54 |
Correct |
65 ms |
14232 KB |
Output is correct |
55 |
Correct |
150 ms |
24148 KB |
Output is correct |
56 |
Correct |
156 ms |
24248 KB |
Output is correct |
57 |
Correct |
65 ms |
14164 KB |
Output is correct |
58 |
Correct |
1 ms |
600 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
3 ms |
860 KB |
Output is correct |
61 |
Correct |
68 ms |
14244 KB |
Output is correct |
62 |
Correct |
1 ms |
344 KB |
Output is correct |
63 |
Correct |
0 ms |
348 KB |
Output is correct |
64 |
Correct |
0 ms |
348 KB |
Output is correct |
65 |
Correct |
39 ms |
6392 KB |
Output is correct |
66 |
Correct |
76 ms |
14284 KB |
Output is correct |
67 |
Correct |
67 ms |
14288 KB |
Output is correct |
68 |
Correct |
65 ms |
14252 KB |
Output is correct |
69 |
Correct |
65 ms |
14360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1372 KB |
Output is correct |
7 |
Correct |
149 ms |
24148 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1624 KB |
Output is correct |
13 |
Correct |
146 ms |
24104 KB |
Output is correct |
14 |
Correct |
1 ms |
356 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
872 KB |
Output is correct |
17 |
Correct |
73 ms |
14360 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
37 ms |
6376 KB |
Output is correct |
21 |
Correct |
168 ms |
24116 KB |
Output is correct |
22 |
Correct |
149 ms |
24232 KB |
Output is correct |
23 |
Correct |
151 ms |
24144 KB |
Output is correct |
24 |
Correct |
150 ms |
24148 KB |
Output is correct |
25 |
Correct |
61 ms |
14164 KB |
Output is correct |
26 |
Correct |
61 ms |
14164 KB |
Output is correct |
27 |
Correct |
159 ms |
24144 KB |
Output is correct |
28 |
Correct |
148 ms |
24228 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
6 ms |
1624 KB |
Output is correct |
37 |
Correct |
155 ms |
24236 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
7 ms |
1624 KB |
Output is correct |
41 |
Correct |
154 ms |
24148 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
3 ms |
860 KB |
Output is correct |
45 |
Correct |
107 ms |
14160 KB |
Output is correct |
46 |
Correct |
1 ms |
344 KB |
Output is correct |
47 |
Correct |
0 ms |
344 KB |
Output is correct |
48 |
Correct |
1 ms |
348 KB |
Output is correct |
49 |
Correct |
49 ms |
6420 KB |
Output is correct |
50 |
Correct |
150 ms |
24148 KB |
Output is correct |
51 |
Correct |
156 ms |
24060 KB |
Output is correct |
52 |
Correct |
156 ms |
24220 KB |
Output is correct |
53 |
Correct |
64 ms |
14168 KB |
Output is correct |
54 |
Correct |
65 ms |
14232 KB |
Output is correct |
55 |
Correct |
150 ms |
24148 KB |
Output is correct |
56 |
Correct |
156 ms |
24248 KB |
Output is correct |
57 |
Correct |
65 ms |
14164 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
1 ms |
348 KB |
Output is correct |
61 |
Correct |
39 ms |
6276 KB |
Output is correct |
62 |
Correct |
152 ms |
24204 KB |
Output is correct |
63 |
Correct |
146 ms |
24120 KB |
Output is correct |
64 |
Correct |
151 ms |
24144 KB |
Output is correct |
65 |
Correct |
0 ms |
344 KB |
Output is correct |
66 |
Correct |
38 ms |
6248 KB |
Output is correct |
67 |
Correct |
156 ms |
24088 KB |
Output is correct |
68 |
Correct |
174 ms |
24124 KB |
Output is correct |
69 |
Correct |
153 ms |
24080 KB |
Output is correct |
70 |
Correct |
1 ms |
344 KB |
Output is correct |
71 |
Correct |
1 ms |
348 KB |
Output is correct |
72 |
Correct |
0 ms |
348 KB |
Output is correct |
73 |
Correct |
43 ms |
6244 KB |
Output is correct |
74 |
Correct |
163 ms |
24088 KB |
Output is correct |
75 |
Correct |
157 ms |
24148 KB |
Output is correct |
76 |
Correct |
158 ms |
24052 KB |
Output is correct |
77 |
Correct |
157 ms |
24212 KB |
Output is correct |
78 |
Correct |
1 ms |
600 KB |
Output is correct |
79 |
Correct |
1 ms |
348 KB |
Output is correct |
80 |
Correct |
3 ms |
860 KB |
Output is correct |
81 |
Correct |
68 ms |
14244 KB |
Output is correct |
82 |
Correct |
1 ms |
344 KB |
Output is correct |
83 |
Correct |
0 ms |
348 KB |
Output is correct |
84 |
Correct |
0 ms |
348 KB |
Output is correct |
85 |
Correct |
39 ms |
6392 KB |
Output is correct |
86 |
Correct |
76 ms |
14284 KB |
Output is correct |
87 |
Correct |
67 ms |
14288 KB |
Output is correct |
88 |
Correct |
65 ms |
14252 KB |
Output is correct |
89 |
Correct |
65 ms |
14360 KB |
Output is correct |
90 |
Correct |
1 ms |
348 KB |
Output is correct |
91 |
Correct |
0 ms |
348 KB |
Output is correct |
92 |
Correct |
4 ms |
964 KB |
Output is correct |
93 |
Correct |
69 ms |
14232 KB |
Output is correct |
94 |
Correct |
1 ms |
348 KB |
Output is correct |
95 |
Correct |
0 ms |
348 KB |
Output is correct |
96 |
Correct |
0 ms |
348 KB |
Output is correct |
97 |
Correct |
16 ms |
3748 KB |
Output is correct |
98 |
Correct |
66 ms |
14360 KB |
Output is correct |
99 |
Correct |
65 ms |
14228 KB |
Output is correct |
100 |
Correct |
76 ms |
14500 KB |
Output is correct |
101 |
Correct |
72 ms |
14148 KB |
Output is correct |
102 |
Correct |
69 ms |
14164 KB |
Output is correct |
103 |
Correct |
70 ms |
14248 KB |
Output is correct |
104 |
Correct |
85 ms |
14232 KB |
Output is correct |
105 |
Correct |
67 ms |
14228 KB |
Output is correct |