#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
vector<vector<ll> >ans,v,w;
vector<pair<ll,ll> >op;
ll n,p1[1009],p2[1009];
ll gp1(ll z)
{
if(p1[z]==z)
return z;
return p1[z]=gp1(p1[z]);
}
ll gp2(ll z)
{
if(p2[z]==z)
return z;
return p2[z]=gp2(p2[z]);
}
void mrg1(ll x,ll y)
{
x=gp1(x),y=gp1(y);
if(x==y)
return;
if(v[y].size()>v[x].size())
swap(x,y);
p1[y]=x;
for(auto z:v[y])
v[x].push_back(z);
}
void mrg2(ll x,ll y)
{
x=gp2(x),y=gp2(y);
if(x==y)
return;
if(w[y].size()>w[x].size())
swap(x,y);
p2[y]=x;
for(auto z:w[y])
w[x].push_back(z);
}
int construct(vector<vector<int> > pp)
{
n=pp.size();
v.resize(n);
w.resize(n);
ans.resize(n);
for(ll i=0; i<n; i++)
ans[i].resize(n);
for(ll i=0; i<n; i++)
p1[i]=p2[i]=i,w[i].push_back(i),v[i]=w[i];
for(ll i=0; i<n; i++)
for(ll j=0; j<n; j++)
{
if(i==j)
continue;
if(pp[i][j]==3)
return 0;
if(pp[i][j]==1)
mrg1(i,j);
else if(pp[i][j]==2)
mrg2(i,j);
}
for(ll i=0; i<n; i++)
{
if(p1[i]==i)
{
for(ll j=0; j<v[i].size()-1; j++)
op.push_back({v[i][j],v[i][j+1]});
}
if(p2[i]==i&&w[i].size()>1)
{
if(w[i].size()<3)
return 0;
for(ll j=0; j<w[i].size()-1; j++)
op.push_back({w[i][j],w[i][j+1]});
op.push_back({w[i][0],w[i].back()});
}
}
for(ll i=0; i<n; i++)
for(ll j=0; j<n; j++)
{
if(pp[i][j]!=0)
continue;
ll x=gp1(i),y=gp1(j);
if(x==y)
return 0;
ll xx=gp2(i),yy=gp2(j);
if(xx==yy)
return 0;
}
for(auto z:op)
ans[z.first][z.second]=ans[z.second][z.first]=1;
build(ans);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:71:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for(ll j=0; j<v[i].size()-1; j++)
| ~^~~~~~~~~~~~~~
supertrees.cpp:78:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for(ll j=0; j<w[i].size()-1; j++)
| ~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
224 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
10 ms |
1220 KB |
Output is correct |
7 |
Correct |
253 ms |
22136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
224 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
10 ms |
1220 KB |
Output is correct |
7 |
Correct |
253 ms |
22136 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
11 ms |
1100 KB |
Output is correct |
13 |
Correct |
267 ms |
22092 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
6 ms |
716 KB |
Output is correct |
17 |
Correct |
119 ms |
12164 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
61 ms |
5772 KB |
Output is correct |
21 |
Correct |
268 ms |
22144 KB |
Output is correct |
22 |
Correct |
265 ms |
22088 KB |
Output is correct |
23 |
Correct |
286 ms |
22144 KB |
Output is correct |
24 |
Correct |
257 ms |
22084 KB |
Output is correct |
25 |
Correct |
99 ms |
12156 KB |
Output is correct |
26 |
Correct |
94 ms |
12236 KB |
Output is correct |
27 |
Correct |
261 ms |
22180 KB |
Output is correct |
28 |
Correct |
264 ms |
22140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
284 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
10 ms |
1132 KB |
Output is correct |
9 |
Correct |
277 ms |
22120 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
10 ms |
1100 KB |
Output is correct |
13 |
Correct |
277 ms |
22064 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
5 ms |
716 KB |
Output is correct |
17 |
Correct |
116 ms |
12156 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
63 ms |
5744 KB |
Output is correct |
22 |
Correct |
255 ms |
22116 KB |
Output is correct |
23 |
Correct |
249 ms |
22084 KB |
Output is correct |
24 |
Correct |
276 ms |
22096 KB |
Output is correct |
25 |
Correct |
97 ms |
12160 KB |
Output is correct |
26 |
Correct |
113 ms |
12160 KB |
Output is correct |
27 |
Correct |
244 ms |
22240 KB |
Output is correct |
28 |
Correct |
264 ms |
22152 KB |
Output is correct |
29 |
Correct |
96 ms |
12176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
224 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
80 ms |
6108 KB |
Output is correct |
5 |
Correct |
265 ms |
22444 KB |
Output is correct |
6 |
Correct |
269 ms |
22372 KB |
Output is correct |
7 |
Correct |
294 ms |
22380 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
63 ms |
6048 KB |
Output is correct |
10 |
Correct |
249 ms |
22440 KB |
Output is correct |
11 |
Correct |
266 ms |
22404 KB |
Output is correct |
12 |
Correct |
270 ms |
22440 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Incorrect |
1 ms |
248 KB |
Too many ways to get from 0 to 4, should be 1 found no less than 2 |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
224 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
10 ms |
1220 KB |
Output is correct |
7 |
Correct |
253 ms |
22136 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
11 ms |
1100 KB |
Output is correct |
13 |
Correct |
267 ms |
22092 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
6 ms |
716 KB |
Output is correct |
17 |
Correct |
119 ms |
12164 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
61 ms |
5772 KB |
Output is correct |
21 |
Correct |
268 ms |
22144 KB |
Output is correct |
22 |
Correct |
265 ms |
22088 KB |
Output is correct |
23 |
Correct |
286 ms |
22144 KB |
Output is correct |
24 |
Correct |
257 ms |
22084 KB |
Output is correct |
25 |
Correct |
99 ms |
12156 KB |
Output is correct |
26 |
Correct |
94 ms |
12236 KB |
Output is correct |
27 |
Correct |
261 ms |
22180 KB |
Output is correct |
28 |
Correct |
264 ms |
22140 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
284 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
10 ms |
1132 KB |
Output is correct |
37 |
Correct |
277 ms |
22120 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
10 ms |
1100 KB |
Output is correct |
41 |
Correct |
277 ms |
22064 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
0 ms |
204 KB |
Output is correct |
44 |
Correct |
5 ms |
716 KB |
Output is correct |
45 |
Correct |
116 ms |
12156 KB |
Output is correct |
46 |
Correct |
0 ms |
204 KB |
Output is correct |
47 |
Correct |
0 ms |
204 KB |
Output is correct |
48 |
Correct |
0 ms |
204 KB |
Output is correct |
49 |
Correct |
63 ms |
5744 KB |
Output is correct |
50 |
Correct |
255 ms |
22116 KB |
Output is correct |
51 |
Correct |
249 ms |
22084 KB |
Output is correct |
52 |
Correct |
276 ms |
22096 KB |
Output is correct |
53 |
Correct |
97 ms |
12160 KB |
Output is correct |
54 |
Correct |
113 ms |
12160 KB |
Output is correct |
55 |
Correct |
244 ms |
22240 KB |
Output is correct |
56 |
Correct |
264 ms |
22152 KB |
Output is correct |
57 |
Correct |
96 ms |
12176 KB |
Output is correct |
58 |
Correct |
1 ms |
204 KB |
Output is correct |
59 |
Correct |
1 ms |
204 KB |
Output is correct |
60 |
Correct |
5 ms |
716 KB |
Output is correct |
61 |
Correct |
137 ms |
12304 KB |
Output is correct |
62 |
Correct |
1 ms |
204 KB |
Output is correct |
63 |
Correct |
1 ms |
204 KB |
Output is correct |
64 |
Correct |
1 ms |
204 KB |
Output is correct |
65 |
Incorrect |
82 ms |
6052 KB |
Too many ways to get from 1 to 183, should be 1 found no less than 2 |
66 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
224 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
10 ms |
1220 KB |
Output is correct |
7 |
Correct |
253 ms |
22136 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
11 ms |
1100 KB |
Output is correct |
13 |
Correct |
267 ms |
22092 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
6 ms |
716 KB |
Output is correct |
17 |
Correct |
119 ms |
12164 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
61 ms |
5772 KB |
Output is correct |
21 |
Correct |
268 ms |
22144 KB |
Output is correct |
22 |
Correct |
265 ms |
22088 KB |
Output is correct |
23 |
Correct |
286 ms |
22144 KB |
Output is correct |
24 |
Correct |
257 ms |
22084 KB |
Output is correct |
25 |
Correct |
99 ms |
12156 KB |
Output is correct |
26 |
Correct |
94 ms |
12236 KB |
Output is correct |
27 |
Correct |
261 ms |
22180 KB |
Output is correct |
28 |
Correct |
264 ms |
22140 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
284 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
10 ms |
1132 KB |
Output is correct |
37 |
Correct |
277 ms |
22120 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
10 ms |
1100 KB |
Output is correct |
41 |
Correct |
277 ms |
22064 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
0 ms |
204 KB |
Output is correct |
44 |
Correct |
5 ms |
716 KB |
Output is correct |
45 |
Correct |
116 ms |
12156 KB |
Output is correct |
46 |
Correct |
0 ms |
204 KB |
Output is correct |
47 |
Correct |
0 ms |
204 KB |
Output is correct |
48 |
Correct |
0 ms |
204 KB |
Output is correct |
49 |
Correct |
63 ms |
5744 KB |
Output is correct |
50 |
Correct |
255 ms |
22116 KB |
Output is correct |
51 |
Correct |
249 ms |
22084 KB |
Output is correct |
52 |
Correct |
276 ms |
22096 KB |
Output is correct |
53 |
Correct |
97 ms |
12160 KB |
Output is correct |
54 |
Correct |
113 ms |
12160 KB |
Output is correct |
55 |
Correct |
244 ms |
22240 KB |
Output is correct |
56 |
Correct |
264 ms |
22152 KB |
Output is correct |
57 |
Correct |
96 ms |
12176 KB |
Output is correct |
58 |
Correct |
1 ms |
204 KB |
Output is correct |
59 |
Correct |
1 ms |
224 KB |
Output is correct |
60 |
Correct |
1 ms |
204 KB |
Output is correct |
61 |
Correct |
80 ms |
6108 KB |
Output is correct |
62 |
Correct |
265 ms |
22444 KB |
Output is correct |
63 |
Correct |
269 ms |
22372 KB |
Output is correct |
64 |
Correct |
294 ms |
22380 KB |
Output is correct |
65 |
Correct |
1 ms |
204 KB |
Output is correct |
66 |
Correct |
63 ms |
6048 KB |
Output is correct |
67 |
Correct |
249 ms |
22440 KB |
Output is correct |
68 |
Correct |
266 ms |
22404 KB |
Output is correct |
69 |
Correct |
270 ms |
22440 KB |
Output is correct |
70 |
Correct |
1 ms |
204 KB |
Output is correct |
71 |
Correct |
1 ms |
204 KB |
Output is correct |
72 |
Incorrect |
1 ms |
248 KB |
Too many ways to get from 0 to 4, should be 1 found no less than 2 |
73 |
Halted |
0 ms |
0 KB |
- |