#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]=merge1(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++)
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
6 ms |
2908 KB |
Output is correct |
7 |
Correct |
123 ms |
31900 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 |
6 ms |
2908 KB |
Output is correct |
7 |
Correct |
123 ms |
31900 KB |
Output is correct |
8 |
Correct |
1 ms |
344 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 |
5 ms |
3012 KB |
Output is correct |
13 |
Correct |
119 ms |
31908 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
3 ms |
2396 KB |
Output is correct |
17 |
Correct |
65 ms |
21928 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
32 ms |
10268 KB |
Output is correct |
21 |
Correct |
118 ms |
32000 KB |
Output is correct |
22 |
Correct |
138 ms |
31828 KB |
Output is correct |
23 |
Correct |
133 ms |
31312 KB |
Output is correct |
24 |
Correct |
120 ms |
31828 KB |
Output is correct |
25 |
Correct |
74 ms |
22096 KB |
Output is correct |
26 |
Correct |
54 ms |
21928 KB |
Output is correct |
27 |
Correct |
126 ms |
31784 KB |
Output is correct |
28 |
Correct |
121 ms |
31828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 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 |
2908 KB |
Output is correct |
9 |
Correct |
139 ms |
31952 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
2908 KB |
Output is correct |
13 |
Correct |
124 ms |
31876 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
5 ms |
2436 KB |
Output is correct |
17 |
Correct |
66 ms |
18004 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
31 ms |
10196 KB |
Output is correct |
22 |
Correct |
121 ms |
31828 KB |
Output is correct |
23 |
Correct |
117 ms |
31928 KB |
Output is correct |
24 |
Correct |
177 ms |
32020 KB |
Output is correct |
25 |
Correct |
52 ms |
18000 KB |
Output is correct |
26 |
Correct |
57 ms |
22096 KB |
Output is correct |
27 |
Correct |
126 ms |
32020 KB |
Output is correct |
28 |
Correct |
131 ms |
31896 KB |
Output is correct |
29 |
Correct |
53 ms |
17960 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 |
32 ms |
10196 KB |
Output is correct |
5 |
Correct |
127 ms |
31908 KB |
Output is correct |
6 |
Correct |
129 ms |
31828 KB |
Output is correct |
7 |
Correct |
127 ms |
31828 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
46 ms |
10244 KB |
Output is correct |
10 |
Correct |
127 ms |
31780 KB |
Output is correct |
11 |
Correct |
133 ms |
31892 KB |
Output is correct |
12 |
Correct |
130 ms |
31852 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
440 KB |
Output is correct |
16 |
Incorrect |
14 ms |
6748 KB |
Answer gives possible 0 while actual possible 1 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
6 ms |
2908 KB |
Output is correct |
7 |
Correct |
123 ms |
31900 KB |
Output is correct |
8 |
Correct |
1 ms |
344 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 |
5 ms |
3012 KB |
Output is correct |
13 |
Correct |
119 ms |
31908 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
3 ms |
2396 KB |
Output is correct |
17 |
Correct |
65 ms |
21928 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
32 ms |
10268 KB |
Output is correct |
21 |
Correct |
118 ms |
32000 KB |
Output is correct |
22 |
Correct |
138 ms |
31828 KB |
Output is correct |
23 |
Correct |
133 ms |
31312 KB |
Output is correct |
24 |
Correct |
120 ms |
31828 KB |
Output is correct |
25 |
Correct |
74 ms |
22096 KB |
Output is correct |
26 |
Correct |
54 ms |
21928 KB |
Output is correct |
27 |
Correct |
126 ms |
31784 KB |
Output is correct |
28 |
Correct |
121 ms |
31828 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
344 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 |
2908 KB |
Output is correct |
37 |
Correct |
139 ms |
31952 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
7 ms |
2908 KB |
Output is correct |
41 |
Correct |
124 ms |
31876 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
5 ms |
2436 KB |
Output is correct |
45 |
Correct |
66 ms |
18004 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
31 ms |
10196 KB |
Output is correct |
50 |
Correct |
121 ms |
31828 KB |
Output is correct |
51 |
Correct |
117 ms |
31928 KB |
Output is correct |
52 |
Correct |
177 ms |
32020 KB |
Output is correct |
53 |
Correct |
52 ms |
18000 KB |
Output is correct |
54 |
Correct |
57 ms |
22096 KB |
Output is correct |
55 |
Correct |
126 ms |
32020 KB |
Output is correct |
56 |
Correct |
131 ms |
31896 KB |
Output is correct |
57 |
Correct |
53 ms |
17960 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
3 ms |
2396 KB |
Output is correct |
61 |
Correct |
60 ms |
18092 KB |
Output is correct |
62 |
Correct |
0 ms |
348 KB |
Output is correct |
63 |
Correct |
0 ms |
348 KB |
Output is correct |
64 |
Correct |
1 ms |
348 KB |
Output is correct |
65 |
Incorrect |
13 ms |
6824 KB |
Answer gives possible 0 while actual possible 1 |
66 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
6 ms |
2908 KB |
Output is correct |
7 |
Correct |
123 ms |
31900 KB |
Output is correct |
8 |
Correct |
1 ms |
344 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 |
5 ms |
3012 KB |
Output is correct |
13 |
Correct |
119 ms |
31908 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
3 ms |
2396 KB |
Output is correct |
17 |
Correct |
65 ms |
21928 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
32 ms |
10268 KB |
Output is correct |
21 |
Correct |
118 ms |
32000 KB |
Output is correct |
22 |
Correct |
138 ms |
31828 KB |
Output is correct |
23 |
Correct |
133 ms |
31312 KB |
Output is correct |
24 |
Correct |
120 ms |
31828 KB |
Output is correct |
25 |
Correct |
74 ms |
22096 KB |
Output is correct |
26 |
Correct |
54 ms |
21928 KB |
Output is correct |
27 |
Correct |
126 ms |
31784 KB |
Output is correct |
28 |
Correct |
121 ms |
31828 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
344 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 |
2908 KB |
Output is correct |
37 |
Correct |
139 ms |
31952 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
7 ms |
2908 KB |
Output is correct |
41 |
Correct |
124 ms |
31876 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
5 ms |
2436 KB |
Output is correct |
45 |
Correct |
66 ms |
18004 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
31 ms |
10196 KB |
Output is correct |
50 |
Correct |
121 ms |
31828 KB |
Output is correct |
51 |
Correct |
117 ms |
31928 KB |
Output is correct |
52 |
Correct |
177 ms |
32020 KB |
Output is correct |
53 |
Correct |
52 ms |
18000 KB |
Output is correct |
54 |
Correct |
57 ms |
22096 KB |
Output is correct |
55 |
Correct |
126 ms |
32020 KB |
Output is correct |
56 |
Correct |
131 ms |
31896 KB |
Output is correct |
57 |
Correct |
53 ms |
17960 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 |
32 ms |
10196 KB |
Output is correct |
62 |
Correct |
127 ms |
31908 KB |
Output is correct |
63 |
Correct |
129 ms |
31828 KB |
Output is correct |
64 |
Correct |
127 ms |
31828 KB |
Output is correct |
65 |
Correct |
0 ms |
348 KB |
Output is correct |
66 |
Correct |
46 ms |
10244 KB |
Output is correct |
67 |
Correct |
127 ms |
31780 KB |
Output is correct |
68 |
Correct |
133 ms |
31892 KB |
Output is correct |
69 |
Correct |
130 ms |
31852 KB |
Output is correct |
70 |
Correct |
1 ms |
344 KB |
Output is correct |
71 |
Correct |
0 ms |
348 KB |
Output is correct |
72 |
Correct |
1 ms |
440 KB |
Output is correct |
73 |
Incorrect |
14 ms |
6748 KB |
Answer gives possible 0 while actual possible 1 |
74 |
Halted |
0 ms |
0 KB |
- |