# Connecting Supertrees SOLUTIONS IOI 2020

Page Contents

## Connecting Supertrees SOLUTION

### 2020 International Olympiad in Informatics Day 1 (Mirror)

Nurseries by the Bay is an enormous nature park in Singapore. In the recreation center there are n towers, known as supertrees. These pinnacles are marked 0 to n−1. We might want to develop a lot of at least zero scaffolds. Each extension interfaces a couple of particular pinnacles and might be crossed in either course. No two extensions ought to associate similar pair of pinnacles.
A way from tower x to tower y is a grouping of at least one pinnacles with the end goal that:
the primary component of the succession is x,
the last component of the grouping is y,
all components of the grouping are unmistakable, and
every two continuous components (towers) in the succession are associated by an extension.
Note that by definition there is actually one way from a pinnacle to itself and the quantity of various ways from tower I to tower j is equivalent to the quantity of various ways from tower j to tower I.
The lead designer responsible for the plan wants for the extensions to be constructed with the end goal that for all 0≤i,j≤n−1 there are actually p[i][j] various ways from tower I to tower j, where 0≤p[i][j]≤3.
Develop a lot of extensions that fulfill the designer’s prerequisites, or establish that it is outlandish.
Usage subtleties
You should execute the accompanying technique:
Duplicate
int construct(int[][] p)
p : a n×n exhibit speaking to the draftsman’s necessities.
On the off chance that a development is conceivable, this strategy should settle on precisely one decision to fabricate (see underneath) to report the development, following which it should bring 1 back.
Something else, the system should restore 0 without settling on any decisions to construct.
This strategy is called precisely once.
The system fabricate is characterized as follows:
Duplicate
void build(int[][] b)
b : a n×n exhibit, with b[i][j]=1 if there is a scaffold associating tower I and pinnacle j, or b[i][j]=0 in any case.
Note that the exhibit must fulfill b[i][j]=b[j][i] for all 0≤i,j≤n−1 and b[i][i]=0 for all 0≤i≤n−1.
Models
Model 1
Duplicate
construct([[1, 1, 2, 2], [1, 1, 2, 2], [2, 2, 1, 2], [2, 2, 2, 1]])
This implies there ought to be actually one way from tower 0 to tower 1. For all different sets of pinnacles (x,y), with the end goal that 0≤x<y≤3, there ought to be actually two ways from tower x to tower y. This can be accomplished with 4 extensions, interfacing sets of pinnacles (0,1), (1,2), (1,3) and (2,3).
To report this arrangement, the build technique should settle on the accompanying decision:
Duplicate
build([[0, 1, 0, 0], [1, 0, 1, 1], [0, 1, 0, 1], [0, 1, 1, 0]])
It should then bring 1 back.
For this situation, there are numerous developments that fit the prerequisites, which would all be viewed as right.
Model 2
Duplicate
construct([[1, 0], [0, 1]])
This implies there ought to be no real way to go between the two pinnacles. This must be fulfilled by having no extensions.
Along these lines, the develop strategy should settle on the accompanying decision:
Duplicate
build([[0, 0], [0, 0]])
After which, the develop system should bring 1 back.
Model 3
Duplicate
construct([[1, 3], [3, 1]])
This implies there ought to be actually 3 ways from tower 0 to tower 1. This arrangement of prerequisites can’t be fulfilled. Accordingly, the develop system should restore 0 without settling on any decision to fabricate.
Requirements
1≤n≤1000
p[i][i]=1 (for all 0≤i≤n−1)
p[i][j]=p[j][i] (for all 0≤i,j≤n−1)
0≤p[i][i]≤3 (for all 0≤i,j≤n−1)
(11 focuses) p[i][j]=1 (for all 0≤i,j≤n−1)
(10 focuses) p[i][j]=0 or 1 (for all 0≤i,j≤n−1)
(19 focuses) p[i][j]=0 or 2 (for all 0≤i,j≤n−1)
(35 focuses) 0≤p[i][j]≤2 (for all 0≤i,j≤n−1) and there is in any event one development fulfilling the necessities.
(21 focuses) 0≤p[i][j]≤2 (for all 0≤i,j≤n−1)
(4 focuses) No extra requirements.