#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=1; j<v[i].size(); j++)
op.push_back({v[i][0],v[i][j]});
}
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=1; j<v[i].size(); 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 |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 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 |
13 ms |
1100 KB |
Output is correct |
7 |
Correct |
264 ms |
22144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 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 |
13 ms |
1100 KB |
Output is correct |
7 |
Correct |
264 ms |
22144 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 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 |
1152 KB |
Output is correct |
13 |
Correct |
241 ms |
22144 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
7 ms |
716 KB |
Output is correct |
17 |
Correct |
121 ms |
12244 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
75 ms |
5828 KB |
Output is correct |
21 |
Correct |
289 ms |
22156 KB |
Output is correct |
22 |
Correct |
275 ms |
22100 KB |
Output is correct |
23 |
Correct |
300 ms |
22140 KB |
Output is correct |
24 |
Correct |
292 ms |
22068 KB |
Output is correct |
25 |
Correct |
107 ms |
12156 KB |
Output is correct |
26 |
Correct |
106 ms |
12160 KB |
Output is correct |
27 |
Correct |
320 ms |
22064 KB |
Output is correct |
28 |
Correct |
254 ms |
22140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
256 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 |
292 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
13 ms |
1152 KB |
Output is correct |
9 |
Correct |
262 ms |
22156 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
14 ms |
1220 KB |
Output is correct |
13 |
Correct |
281 ms |
22104 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
5 ms |
708 KB |
Output is correct |
17 |
Correct |
140 ms |
12172 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
74 ms |
5756 KB |
Output is correct |
22 |
Correct |
291 ms |
22056 KB |
Output is correct |
23 |
Correct |
292 ms |
22140 KB |
Output is correct |
24 |
Correct |
300 ms |
22160 KB |
Output is correct |
25 |
Correct |
127 ms |
12172 KB |
Output is correct |
26 |
Correct |
111 ms |
12156 KB |
Output is correct |
27 |
Correct |
295 ms |
22124 KB |
Output is correct |
28 |
Correct |
294 ms |
22144 KB |
Output is correct |
29 |
Correct |
128 ms |
12160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
240 KB |
Output is correct |
4 |
Correct |
66 ms |
5720 KB |
Output is correct |
5 |
Correct |
256 ms |
22160 KB |
Output is correct |
6 |
Correct |
272 ms |
22136 KB |
Output is correct |
7 |
Correct |
271 ms |
22148 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
74 ms |
5736 KB |
Output is correct |
10 |
Correct |
284 ms |
22100 KB |
Output is correct |
11 |
Correct |
272 ms |
22072 KB |
Output is correct |
12 |
Correct |
317 ms |
22068 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 |
204 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 |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 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 |
13 ms |
1100 KB |
Output is correct |
7 |
Correct |
264 ms |
22144 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 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 |
1152 KB |
Output is correct |
13 |
Correct |
241 ms |
22144 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
7 ms |
716 KB |
Output is correct |
17 |
Correct |
121 ms |
12244 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
75 ms |
5828 KB |
Output is correct |
21 |
Correct |
289 ms |
22156 KB |
Output is correct |
22 |
Correct |
275 ms |
22100 KB |
Output is correct |
23 |
Correct |
300 ms |
22140 KB |
Output is correct |
24 |
Correct |
292 ms |
22068 KB |
Output is correct |
25 |
Correct |
107 ms |
12156 KB |
Output is correct |
26 |
Correct |
106 ms |
12160 KB |
Output is correct |
27 |
Correct |
320 ms |
22064 KB |
Output is correct |
28 |
Correct |
254 ms |
22140 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
256 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 |
292 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
13 ms |
1152 KB |
Output is correct |
37 |
Correct |
262 ms |
22156 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
14 ms |
1220 KB |
Output is correct |
41 |
Correct |
281 ms |
22104 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
1 ms |
204 KB |
Output is correct |
44 |
Correct |
5 ms |
708 KB |
Output is correct |
45 |
Correct |
140 ms |
12172 KB |
Output is correct |
46 |
Correct |
1 ms |
204 KB |
Output is correct |
47 |
Correct |
0 ms |
204 KB |
Output is correct |
48 |
Correct |
1 ms |
204 KB |
Output is correct |
49 |
Correct |
74 ms |
5756 KB |
Output is correct |
50 |
Correct |
291 ms |
22056 KB |
Output is correct |
51 |
Correct |
292 ms |
22140 KB |
Output is correct |
52 |
Correct |
300 ms |
22160 KB |
Output is correct |
53 |
Correct |
127 ms |
12172 KB |
Output is correct |
54 |
Correct |
111 ms |
12156 KB |
Output is correct |
55 |
Correct |
295 ms |
22124 KB |
Output is correct |
56 |
Correct |
294 ms |
22144 KB |
Output is correct |
57 |
Correct |
128 ms |
12160 KB |
Output is correct |
58 |
Correct |
0 ms |
204 KB |
Output is correct |
59 |
Correct |
1 ms |
204 KB |
Output is correct |
60 |
Correct |
7 ms |
716 KB |
Output is correct |
61 |
Correct |
117 ms |
12292 KB |
Output is correct |
62 |
Correct |
1 ms |
204 KB |
Output is correct |
63 |
Correct |
1 ms |
204 KB |
Output is correct |
64 |
Correct |
0 ms |
204 KB |
Output is correct |
65 |
Incorrect |
72 ms |
5828 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 |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 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 |
13 ms |
1100 KB |
Output is correct |
7 |
Correct |
264 ms |
22144 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 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 |
1152 KB |
Output is correct |
13 |
Correct |
241 ms |
22144 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
7 ms |
716 KB |
Output is correct |
17 |
Correct |
121 ms |
12244 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
75 ms |
5828 KB |
Output is correct |
21 |
Correct |
289 ms |
22156 KB |
Output is correct |
22 |
Correct |
275 ms |
22100 KB |
Output is correct |
23 |
Correct |
300 ms |
22140 KB |
Output is correct |
24 |
Correct |
292 ms |
22068 KB |
Output is correct |
25 |
Correct |
107 ms |
12156 KB |
Output is correct |
26 |
Correct |
106 ms |
12160 KB |
Output is correct |
27 |
Correct |
320 ms |
22064 KB |
Output is correct |
28 |
Correct |
254 ms |
22140 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
256 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 |
292 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
13 ms |
1152 KB |
Output is correct |
37 |
Correct |
262 ms |
22156 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
14 ms |
1220 KB |
Output is correct |
41 |
Correct |
281 ms |
22104 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
1 ms |
204 KB |
Output is correct |
44 |
Correct |
5 ms |
708 KB |
Output is correct |
45 |
Correct |
140 ms |
12172 KB |
Output is correct |
46 |
Correct |
1 ms |
204 KB |
Output is correct |
47 |
Correct |
0 ms |
204 KB |
Output is correct |
48 |
Correct |
1 ms |
204 KB |
Output is correct |
49 |
Correct |
74 ms |
5756 KB |
Output is correct |
50 |
Correct |
291 ms |
22056 KB |
Output is correct |
51 |
Correct |
292 ms |
22140 KB |
Output is correct |
52 |
Correct |
300 ms |
22160 KB |
Output is correct |
53 |
Correct |
127 ms |
12172 KB |
Output is correct |
54 |
Correct |
111 ms |
12156 KB |
Output is correct |
55 |
Correct |
295 ms |
22124 KB |
Output is correct |
56 |
Correct |
294 ms |
22144 KB |
Output is correct |
57 |
Correct |
128 ms |
12160 KB |
Output is correct |
58 |
Correct |
1 ms |
204 KB |
Output is correct |
59 |
Correct |
0 ms |
256 KB |
Output is correct |
60 |
Correct |
1 ms |
240 KB |
Output is correct |
61 |
Correct |
66 ms |
5720 KB |
Output is correct |
62 |
Correct |
256 ms |
22160 KB |
Output is correct |
63 |
Correct |
272 ms |
22136 KB |
Output is correct |
64 |
Correct |
271 ms |
22148 KB |
Output is correct |
65 |
Correct |
1 ms |
204 KB |
Output is correct |
66 |
Correct |
74 ms |
5736 KB |
Output is correct |
67 |
Correct |
284 ms |
22100 KB |
Output is correct |
68 |
Correct |
272 ms |
22072 KB |
Output is correct |
69 |
Correct |
317 ms |
22068 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 |
204 KB |
Too many ways to get from 0 to 4, should be 1 found no less than 2 |
73 |
Halted |
0 ms |
0 KB |
- |