#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
vector <vector<int>> sol;
int sef[1001];
int ef(int x)
{
if(sef[x]==x)
return x;
else
return sef[x]=ef(sef[x]);
}
vector <int> comp[1001],rez,l;
bool ok[1001];
int construct(vector <vector <int>> p)
{
int i,j,nr,n;
n=p.size();
for(i=0;i<n;i++)
sef[i]=i;
l.resize(n);
for(i=0;i<n;i++)
sol.push_back(l);
for(i=0;i<n;i++)
{
for(j=0,nr=0;j<n;j++)
{
if(p[i][j]==3)
return 0;
if(p[i][j]==0&&ef(i)==ef(j))
return 0;
if(p[i][j]>0)
sef[ef(i)]=ef(j);
if(p[i][j]==2)
nr++;
if(p[i][j]==1&&i!=j)
ok[i]=true;
}
if(nr==1)
return 0;
}
for(i=0;i<n;i++)
comp[ef(i)].push_back(i);
for(i=0;i<n;i++)
sef[i]=-1;
for(i=0;i<n;i++)
{
if(!comp[i].empty())
{
rez.clear();
for(auto x : comp[i])
{
if(!ok[x])/// se alfa pe ciclu
rez.push_back(x);
else
{
if(sef[x]==-1)///nou lant
{
rez.push_back(x);
sef[x]=x;
for(j=0;j<n;j++)
{
if(p[x][j]==1&&x!=j)
{
if(sef[j]==-1)
{
sef[j]=x;
sol[x][j]=sol[j][x]=1;
}
else
return 0;
}
}
}
else
{
for(j=0;j<n;j++)
{
if(p[x][j]==2&&sef[x]==sef[j])
return 0;
if(p[x][j]==1&&sef[x]!=sef[j])
return 0;
}
}
}
}
if(rez.size()>2)
{
for(j=1;j<rez.size();j++)
{
sol[rez[j-1]][rez[j]]=sol[rez[j]][rez[j-1]]=1;
}
sol[rez[0]][rez[j-1]]=sol[rez[j-1]][rez[0]]=1;
}
}
}
build(sol);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:89:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | for(j=1;j<rez.size();j++)
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
7 ms |
1360 KB |
Output is correct |
7 |
Correct |
127 ms |
24056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
7 ms |
1360 KB |
Output is correct |
7 |
Correct |
127 ms |
24056 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
6 ms |
1360 KB |
Output is correct |
13 |
Correct |
144 ms |
23972 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
3 ms |
848 KB |
Output is correct |
17 |
Correct |
58 ms |
14248 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
31 ms |
6224 KB |
Output is correct |
21 |
Correct |
182 ms |
23976 KB |
Output is correct |
22 |
Correct |
144 ms |
24144 KB |
Output is correct |
23 |
Correct |
129 ms |
24136 KB |
Output is correct |
24 |
Correct |
141 ms |
24136 KB |
Output is correct |
25 |
Correct |
65 ms |
14152 KB |
Output is correct |
26 |
Correct |
54 ms |
14168 KB |
Output is correct |
27 |
Correct |
131 ms |
24136 KB |
Output is correct |
28 |
Correct |
132 ms |
23972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
504 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
464 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
8 ms |
1412 KB |
Output is correct |
9 |
Correct |
152 ms |
24100 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
6 ms |
1372 KB |
Output is correct |
13 |
Correct |
123 ms |
24016 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
3 ms |
848 KB |
Output is correct |
17 |
Correct |
59 ms |
14256 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
33 ms |
6224 KB |
Output is correct |
22 |
Correct |
122 ms |
24112 KB |
Output is correct |
23 |
Correct |
131 ms |
24020 KB |
Output is correct |
24 |
Correct |
144 ms |
24100 KB |
Output is correct |
25 |
Correct |
57 ms |
14044 KB |
Output is correct |
26 |
Correct |
58 ms |
14112 KB |
Output is correct |
27 |
Correct |
132 ms |
24136 KB |
Output is correct |
28 |
Correct |
135 ms |
23980 KB |
Output is correct |
29 |
Correct |
77 ms |
14152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
32 ms |
6324 KB |
Output is correct |
5 |
Correct |
128 ms |
24136 KB |
Output is correct |
6 |
Correct |
129 ms |
24136 KB |
Output is correct |
7 |
Correct |
133 ms |
24100 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
32 ms |
6236 KB |
Output is correct |
10 |
Correct |
151 ms |
24112 KB |
Output is correct |
11 |
Correct |
126 ms |
24104 KB |
Output is correct |
12 |
Correct |
153 ms |
23976 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
508 KB |
Output is correct |
16 |
Correct |
33 ms |
6432 KB |
Output is correct |
17 |
Correct |
132 ms |
23972 KB |
Output is correct |
18 |
Correct |
124 ms |
23968 KB |
Output is correct |
19 |
Correct |
124 ms |
24136 KB |
Output is correct |
20 |
Correct |
132 ms |
24136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
7 ms |
1360 KB |
Output is correct |
7 |
Correct |
127 ms |
24056 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
6 ms |
1360 KB |
Output is correct |
13 |
Correct |
144 ms |
23972 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
3 ms |
848 KB |
Output is correct |
17 |
Correct |
58 ms |
14248 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
31 ms |
6224 KB |
Output is correct |
21 |
Correct |
182 ms |
23976 KB |
Output is correct |
22 |
Correct |
144 ms |
24144 KB |
Output is correct |
23 |
Correct |
129 ms |
24136 KB |
Output is correct |
24 |
Correct |
141 ms |
24136 KB |
Output is correct |
25 |
Correct |
65 ms |
14152 KB |
Output is correct |
26 |
Correct |
54 ms |
14168 KB |
Output is correct |
27 |
Correct |
131 ms |
24136 KB |
Output is correct |
28 |
Correct |
132 ms |
23972 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
504 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
464 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
8 ms |
1412 KB |
Output is correct |
37 |
Correct |
152 ms |
24100 KB |
Output is correct |
38 |
Correct |
1 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
6 ms |
1372 KB |
Output is correct |
41 |
Correct |
123 ms |
24016 KB |
Output is correct |
42 |
Correct |
1 ms |
468 KB |
Output is correct |
43 |
Correct |
1 ms |
336 KB |
Output is correct |
44 |
Correct |
3 ms |
848 KB |
Output is correct |
45 |
Correct |
59 ms |
14256 KB |
Output is correct |
46 |
Correct |
1 ms |
336 KB |
Output is correct |
47 |
Correct |
1 ms |
336 KB |
Output is correct |
48 |
Correct |
1 ms |
336 KB |
Output is correct |
49 |
Correct |
33 ms |
6224 KB |
Output is correct |
50 |
Correct |
122 ms |
24112 KB |
Output is correct |
51 |
Correct |
131 ms |
24020 KB |
Output is correct |
52 |
Correct |
144 ms |
24100 KB |
Output is correct |
53 |
Correct |
57 ms |
14044 KB |
Output is correct |
54 |
Correct |
58 ms |
14112 KB |
Output is correct |
55 |
Correct |
132 ms |
24136 KB |
Output is correct |
56 |
Correct |
135 ms |
23980 KB |
Output is correct |
57 |
Correct |
77 ms |
14152 KB |
Output is correct |
58 |
Correct |
1 ms |
336 KB |
Output is correct |
59 |
Correct |
1 ms |
336 KB |
Output is correct |
60 |
Correct |
3 ms |
992 KB |
Output is correct |
61 |
Correct |
58 ms |
14164 KB |
Output is correct |
62 |
Correct |
1 ms |
336 KB |
Output is correct |
63 |
Correct |
1 ms |
468 KB |
Output is correct |
64 |
Correct |
1 ms |
336 KB |
Output is correct |
65 |
Correct |
32 ms |
6316 KB |
Output is correct |
66 |
Correct |
55 ms |
14152 KB |
Output is correct |
67 |
Correct |
60 ms |
14152 KB |
Output is correct |
68 |
Correct |
60 ms |
14152 KB |
Output is correct |
69 |
Correct |
53 ms |
14252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
7 ms |
1360 KB |
Output is correct |
7 |
Correct |
127 ms |
24056 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
6 ms |
1360 KB |
Output is correct |
13 |
Correct |
144 ms |
23972 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
3 ms |
848 KB |
Output is correct |
17 |
Correct |
58 ms |
14248 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
31 ms |
6224 KB |
Output is correct |
21 |
Correct |
182 ms |
23976 KB |
Output is correct |
22 |
Correct |
144 ms |
24144 KB |
Output is correct |
23 |
Correct |
129 ms |
24136 KB |
Output is correct |
24 |
Correct |
141 ms |
24136 KB |
Output is correct |
25 |
Correct |
65 ms |
14152 KB |
Output is correct |
26 |
Correct |
54 ms |
14168 KB |
Output is correct |
27 |
Correct |
131 ms |
24136 KB |
Output is correct |
28 |
Correct |
132 ms |
23972 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
504 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
464 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
8 ms |
1412 KB |
Output is correct |
37 |
Correct |
152 ms |
24100 KB |
Output is correct |
38 |
Correct |
1 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
6 ms |
1372 KB |
Output is correct |
41 |
Correct |
123 ms |
24016 KB |
Output is correct |
42 |
Correct |
1 ms |
468 KB |
Output is correct |
43 |
Correct |
1 ms |
336 KB |
Output is correct |
44 |
Correct |
3 ms |
848 KB |
Output is correct |
45 |
Correct |
59 ms |
14256 KB |
Output is correct |
46 |
Correct |
1 ms |
336 KB |
Output is correct |
47 |
Correct |
1 ms |
336 KB |
Output is correct |
48 |
Correct |
1 ms |
336 KB |
Output is correct |
49 |
Correct |
33 ms |
6224 KB |
Output is correct |
50 |
Correct |
122 ms |
24112 KB |
Output is correct |
51 |
Correct |
131 ms |
24020 KB |
Output is correct |
52 |
Correct |
144 ms |
24100 KB |
Output is correct |
53 |
Correct |
57 ms |
14044 KB |
Output is correct |
54 |
Correct |
58 ms |
14112 KB |
Output is correct |
55 |
Correct |
132 ms |
24136 KB |
Output is correct |
56 |
Correct |
135 ms |
23980 KB |
Output is correct |
57 |
Correct |
77 ms |
14152 KB |
Output is correct |
58 |
Correct |
1 ms |
336 KB |
Output is correct |
59 |
Correct |
1 ms |
336 KB |
Output is correct |
60 |
Correct |
1 ms |
336 KB |
Output is correct |
61 |
Correct |
32 ms |
6324 KB |
Output is correct |
62 |
Correct |
128 ms |
24136 KB |
Output is correct |
63 |
Correct |
129 ms |
24136 KB |
Output is correct |
64 |
Correct |
133 ms |
24100 KB |
Output is correct |
65 |
Correct |
1 ms |
336 KB |
Output is correct |
66 |
Correct |
32 ms |
6236 KB |
Output is correct |
67 |
Correct |
151 ms |
24112 KB |
Output is correct |
68 |
Correct |
126 ms |
24104 KB |
Output is correct |
69 |
Correct |
153 ms |
23976 KB |
Output is correct |
70 |
Correct |
1 ms |
336 KB |
Output is correct |
71 |
Correct |
1 ms |
336 KB |
Output is correct |
72 |
Correct |
1 ms |
508 KB |
Output is correct |
73 |
Correct |
33 ms |
6432 KB |
Output is correct |
74 |
Correct |
132 ms |
23972 KB |
Output is correct |
75 |
Correct |
124 ms |
23968 KB |
Output is correct |
76 |
Correct |
124 ms |
24136 KB |
Output is correct |
77 |
Correct |
132 ms |
24136 KB |
Output is correct |
78 |
Correct |
1 ms |
336 KB |
Output is correct |
79 |
Correct |
1 ms |
336 KB |
Output is correct |
80 |
Correct |
3 ms |
992 KB |
Output is correct |
81 |
Correct |
58 ms |
14164 KB |
Output is correct |
82 |
Correct |
1 ms |
336 KB |
Output is correct |
83 |
Correct |
1 ms |
468 KB |
Output is correct |
84 |
Correct |
1 ms |
336 KB |
Output is correct |
85 |
Correct |
32 ms |
6316 KB |
Output is correct |
86 |
Correct |
55 ms |
14152 KB |
Output is correct |
87 |
Correct |
60 ms |
14152 KB |
Output is correct |
88 |
Correct |
60 ms |
14152 KB |
Output is correct |
89 |
Correct |
53 ms |
14252 KB |
Output is correct |
90 |
Correct |
1 ms |
336 KB |
Output is correct |
91 |
Correct |
1 ms |
336 KB |
Output is correct |
92 |
Correct |
4 ms |
848 KB |
Output is correct |
93 |
Correct |
61 ms |
14152 KB |
Output is correct |
94 |
Correct |
1 ms |
336 KB |
Output is correct |
95 |
Correct |
1 ms |
336 KB |
Output is correct |
96 |
Correct |
1 ms |
336 KB |
Output is correct |
97 |
Correct |
14 ms |
3920 KB |
Output is correct |
98 |
Correct |
55 ms |
14152 KB |
Output is correct |
99 |
Correct |
54 ms |
14252 KB |
Output is correct |
100 |
Correct |
53 ms |
14248 KB |
Output is correct |
101 |
Correct |
55 ms |
14040 KB |
Output is correct |
102 |
Correct |
51 ms |
14120 KB |
Output is correct |
103 |
Correct |
52 ms |
14156 KB |
Output is correct |
104 |
Correct |
70 ms |
14152 KB |
Output is correct |
105 |
Correct |
62 ms |
14152 KB |
Output is correct |