#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int N=1e3;
int reach[N][N],tree_case[N][N];
int par[N],par1[N];
void init(int n)
{
for(int i=0;i<n;i++)
par[i]=par1[i]=i;
}
int get(int x)
{
if(par[x]==x)return x;
return par[x]=get(par[x]);
}
int get1(int x)
{
if(par1[x]==x)return x;
return par1[x]=get1(par1[x]);
}
bool merge(int x,int y)
{
x=get(x);
y=get(y);
if(x==y)return 0;
par[y]=x;
return 1;
}
bool merge1(int x,int y)
{
x=get1(x);
y=get1(y);
if(x==y)return 0;
par1[y]=x;
return 1;
}
vector<int> ma[N];
int head;
void dfs(int x)
{
reach[head][x]=1;
for(auto y:ma[x])
if(!reach[head][y])
dfs(y);
}
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
init(n);
for(int i=0;i<n;i++)
{
if(p[i][i]!=1) // i i is always one
return 0;
for(int j=0;j<n;j++)
tree_case[i][j]=reach[i][j]=0;
}
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(p[i][j]==1)
{
tree_case[i][j]=tree_case[j][i]=merge(i,j);
}
}
}
for(int i=0;i<n;i++)
{
if(i==get(i))
{
vector<int> cur={i};
for(int j=i+1;j<n;j++)
{
if(get(j)==j)
{
bool han=1;
for(auto k:cur)
{
if(p[k][j]!=2)
{
han=0;
break;
}
}
if(han)
{
cur.push_back(j);
merge(i,j);
}
}
}
if(cur.size()==1)continue;
if(cur.size()==2)
return 0;
cur.push_back(i);
for(int j=1;j<cur.size();j++)
{
int x=cur[j-1];
int y=cur[j];
tree_case[x][y]=tree_case[y][x]=1;
merge(x,y);
}
}
}
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(tree_case[i][j])
{
ma[i].push_back(j);
ma[j].push_back(i);
}
}
}
vector<vector<int>> answer(n,vector<int>(n,0));
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
answer[i][j]=tree_case[i][j];
reach[i][j]=0;
}
head=i;
dfs(i);
for(int j=0;j<n;j++)
{
p[i][j]-=(p[i][j]==2);// make 2 to 1
if(reach[i][j]!=p[i][j])
{
return 0;
}
}
}
build(answer);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:96:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
96 | for(int j=1;j<cur.size();j++)
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
356 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 |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
2876 KB |
Output is correct |
7 |
Correct |
133 ms |
30012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
356 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 |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
2876 KB |
Output is correct |
7 |
Correct |
133 ms |
30012 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
6 ms |
2908 KB |
Output is correct |
13 |
Correct |
123 ms |
30004 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
2420 KB |
Output is correct |
17 |
Correct |
81 ms |
20016 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
34 ms |
9808 KB |
Output is correct |
21 |
Correct |
139 ms |
29988 KB |
Output is correct |
22 |
Correct |
142 ms |
29868 KB |
Output is correct |
23 |
Correct |
135 ms |
29896 KB |
Output is correct |
24 |
Correct |
127 ms |
30032 KB |
Output is correct |
25 |
Correct |
56 ms |
20048 KB |
Output is correct |
26 |
Correct |
62 ms |
20052 KB |
Output is correct |
27 |
Correct |
194 ms |
30004 KB |
Output is correct |
28 |
Correct |
123 ms |
29996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
11 ms |
3012 KB |
Output is correct |
9 |
Correct |
123 ms |
32000 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
6 ms |
2908 KB |
Output is correct |
13 |
Correct |
131 ms |
32036 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
6 ms |
2392 KB |
Output is correct |
17 |
Correct |
84 ms |
18084 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
32 ms |
10332 KB |
Output is correct |
22 |
Correct |
127 ms |
31828 KB |
Output is correct |
23 |
Correct |
142 ms |
31824 KB |
Output is correct |
24 |
Correct |
190 ms |
31896 KB |
Output is correct |
25 |
Correct |
91 ms |
18004 KB |
Output is correct |
26 |
Correct |
99 ms |
22096 KB |
Output is correct |
27 |
Correct |
119 ms |
31828 KB |
Output is correct |
28 |
Correct |
135 ms |
32040 KB |
Output is correct |
29 |
Correct |
96 ms |
18004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
65 ms |
9676 KB |
Output is correct |
5 |
Correct |
164 ms |
30004 KB |
Output is correct |
6 |
Correct |
124 ms |
30000 KB |
Output is correct |
7 |
Correct |
165 ms |
30032 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
38 ms |
9784 KB |
Output is correct |
10 |
Correct |
125 ms |
30008 KB |
Output is correct |
11 |
Correct |
123 ms |
30036 KB |
Output is correct |
12 |
Correct |
130 ms |
29896 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
40 ms |
9644 KB |
Output is correct |
17 |
Correct |
126 ms |
30036 KB |
Output is correct |
18 |
Correct |
134 ms |
30008 KB |
Output is correct |
19 |
Correct |
123 ms |
29996 KB |
Output is correct |
20 |
Correct |
129 ms |
29792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
356 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 |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
2876 KB |
Output is correct |
7 |
Correct |
133 ms |
30012 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
6 ms |
2908 KB |
Output is correct |
13 |
Correct |
123 ms |
30004 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
2420 KB |
Output is correct |
17 |
Correct |
81 ms |
20016 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
34 ms |
9808 KB |
Output is correct |
21 |
Correct |
139 ms |
29988 KB |
Output is correct |
22 |
Correct |
142 ms |
29868 KB |
Output is correct |
23 |
Correct |
135 ms |
29896 KB |
Output is correct |
24 |
Correct |
127 ms |
30032 KB |
Output is correct |
25 |
Correct |
56 ms |
20048 KB |
Output is correct |
26 |
Correct |
62 ms |
20052 KB |
Output is correct |
27 |
Correct |
194 ms |
30004 KB |
Output is correct |
28 |
Correct |
123 ms |
29996 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
11 ms |
3012 KB |
Output is correct |
37 |
Correct |
123 ms |
32000 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
468 KB |
Output is correct |
40 |
Correct |
6 ms |
2908 KB |
Output is correct |
41 |
Correct |
131 ms |
32036 KB |
Output is correct |
42 |
Correct |
0 ms |
344 KB |
Output is correct |
43 |
Correct |
1 ms |
344 KB |
Output is correct |
44 |
Correct |
6 ms |
2392 KB |
Output is correct |
45 |
Correct |
84 ms |
18084 KB |
Output is correct |
46 |
Correct |
1 ms |
348 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
32 ms |
10332 KB |
Output is correct |
50 |
Correct |
127 ms |
31828 KB |
Output is correct |
51 |
Correct |
142 ms |
31824 KB |
Output is correct |
52 |
Correct |
190 ms |
31896 KB |
Output is correct |
53 |
Correct |
91 ms |
18004 KB |
Output is correct |
54 |
Correct |
99 ms |
22096 KB |
Output is correct |
55 |
Correct |
119 ms |
31828 KB |
Output is correct |
56 |
Correct |
135 ms |
32040 KB |
Output is correct |
57 |
Correct |
96 ms |
18004 KB |
Output is correct |
58 |
Correct |
1 ms |
344 KB |
Output is correct |
59 |
Correct |
1 ms |
600 KB |
Output is correct |
60 |
Correct |
4 ms |
2396 KB |
Output is correct |
61 |
Correct |
69 ms |
22048 KB |
Output is correct |
62 |
Correct |
0 ms |
604 KB |
Output is correct |
63 |
Correct |
0 ms |
348 KB |
Output is correct |
64 |
Correct |
1 ms |
348 KB |
Output is correct |
65 |
Correct |
64 ms |
10324 KB |
Output is correct |
66 |
Correct |
58 ms |
22096 KB |
Output is correct |
67 |
Correct |
59 ms |
22096 KB |
Output is correct |
68 |
Correct |
57 ms |
21928 KB |
Output is correct |
69 |
Correct |
53 ms |
18004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
356 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 |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
2876 KB |
Output is correct |
7 |
Correct |
133 ms |
30012 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
6 ms |
2908 KB |
Output is correct |
13 |
Correct |
123 ms |
30004 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
2420 KB |
Output is correct |
17 |
Correct |
81 ms |
20016 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
34 ms |
9808 KB |
Output is correct |
21 |
Correct |
139 ms |
29988 KB |
Output is correct |
22 |
Correct |
142 ms |
29868 KB |
Output is correct |
23 |
Correct |
135 ms |
29896 KB |
Output is correct |
24 |
Correct |
127 ms |
30032 KB |
Output is correct |
25 |
Correct |
56 ms |
20048 KB |
Output is correct |
26 |
Correct |
62 ms |
20052 KB |
Output is correct |
27 |
Correct |
194 ms |
30004 KB |
Output is correct |
28 |
Correct |
123 ms |
29996 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
11 ms |
3012 KB |
Output is correct |
37 |
Correct |
123 ms |
32000 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
468 KB |
Output is correct |
40 |
Correct |
6 ms |
2908 KB |
Output is correct |
41 |
Correct |
131 ms |
32036 KB |
Output is correct |
42 |
Correct |
0 ms |
344 KB |
Output is correct |
43 |
Correct |
1 ms |
344 KB |
Output is correct |
44 |
Correct |
6 ms |
2392 KB |
Output is correct |
45 |
Correct |
84 ms |
18084 KB |
Output is correct |
46 |
Correct |
1 ms |
348 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
32 ms |
10332 KB |
Output is correct |
50 |
Correct |
127 ms |
31828 KB |
Output is correct |
51 |
Correct |
142 ms |
31824 KB |
Output is correct |
52 |
Correct |
190 ms |
31896 KB |
Output is correct |
53 |
Correct |
91 ms |
18004 KB |
Output is correct |
54 |
Correct |
99 ms |
22096 KB |
Output is correct |
55 |
Correct |
119 ms |
31828 KB |
Output is correct |
56 |
Correct |
135 ms |
32040 KB |
Output is correct |
57 |
Correct |
96 ms |
18004 KB |
Output is correct |
58 |
Correct |
1 ms |
348 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
65 ms |
9676 KB |
Output is correct |
62 |
Correct |
164 ms |
30004 KB |
Output is correct |
63 |
Correct |
124 ms |
30000 KB |
Output is correct |
64 |
Correct |
165 ms |
30032 KB |
Output is correct |
65 |
Correct |
1 ms |
348 KB |
Output is correct |
66 |
Correct |
38 ms |
9784 KB |
Output is correct |
67 |
Correct |
125 ms |
30008 KB |
Output is correct |
68 |
Correct |
123 ms |
30036 KB |
Output is correct |
69 |
Correct |
130 ms |
29896 KB |
Output is correct |
70 |
Correct |
0 ms |
348 KB |
Output is correct |
71 |
Correct |
1 ms |
348 KB |
Output is correct |
72 |
Correct |
1 ms |
348 KB |
Output is correct |
73 |
Correct |
40 ms |
9644 KB |
Output is correct |
74 |
Correct |
126 ms |
30036 KB |
Output is correct |
75 |
Correct |
134 ms |
30008 KB |
Output is correct |
76 |
Correct |
123 ms |
29996 KB |
Output is correct |
77 |
Correct |
129 ms |
29792 KB |
Output is correct |
78 |
Correct |
1 ms |
344 KB |
Output is correct |
79 |
Correct |
1 ms |
600 KB |
Output is correct |
80 |
Correct |
4 ms |
2396 KB |
Output is correct |
81 |
Correct |
69 ms |
22048 KB |
Output is correct |
82 |
Correct |
0 ms |
604 KB |
Output is correct |
83 |
Correct |
0 ms |
348 KB |
Output is correct |
84 |
Correct |
1 ms |
348 KB |
Output is correct |
85 |
Correct |
64 ms |
10324 KB |
Output is correct |
86 |
Correct |
58 ms |
22096 KB |
Output is correct |
87 |
Correct |
59 ms |
22096 KB |
Output is correct |
88 |
Correct |
57 ms |
21928 KB |
Output is correct |
89 |
Correct |
53 ms |
18004 KB |
Output is correct |
90 |
Correct |
0 ms |
348 KB |
Output is correct |
91 |
Correct |
1 ms |
348 KB |
Output is correct |
92 |
Correct |
4 ms |
2396 KB |
Output is correct |
93 |
Correct |
62 ms |
22052 KB |
Output is correct |
94 |
Correct |
1 ms |
344 KB |
Output is correct |
95 |
Correct |
1 ms |
348 KB |
Output is correct |
96 |
Correct |
1 ms |
348 KB |
Output is correct |
97 |
Correct |
18 ms |
7716 KB |
Output is correct |
98 |
Correct |
59 ms |
22100 KB |
Output is correct |
99 |
Correct |
94 ms |
22044 KB |
Output is correct |
100 |
Correct |
56 ms |
21864 KB |
Output is correct |
101 |
Correct |
56 ms |
21964 KB |
Output is correct |
102 |
Correct |
61 ms |
21844 KB |
Output is correct |
103 |
Correct |
56 ms |
18124 KB |
Output is correct |
104 |
Correct |
55 ms |
21924 KB |
Output is correct |
105 |
Correct |
61 ms |
21840 KB |
Output is correct |