Connecting Supertrees
Time limit1sMemory limit1024 MB
Given an n by n matrix of path counts (each 0 to 3), build a simple undirected graph of bridges that matches every p[i][j], or report that none exists.
- Level
Hard8 of 10
- Topics
- Graph, Union-find, Implementation
- Solved
- No attempts yet
Problem
Gardens by the Bay is a large nature park in Singapore. The park has towers, known as supertrees, labelled 0 to . Build a set of zero or more bridges. Each bridge connects a pair of distinct towers and can be traversed in either direction. No two bridges may connect the same pair of towers.
A path from tower to tower is a sequence of one or more towers such that:
- the first element is ,
- the last element is ,
- all elements are distinct, and
- each two consecutive elements are connected by a bridge.
By definition, there is exactly one path from a tower to itself. The number of paths from tower to tower is the same as the number of paths from tower to tower .
The architect wants the bridges built so that for all there are exactly different paths from tower to tower , where . Construct a set of bridges that meets these requirements, or determine that it is impossible.
Constraints
- for all
- for all
- for all