https://github.com/zdimension/stablewall
Solution to the GKS 2020 Round C problem "Stable Wall"
https://github.com/zdimension/stablewall
Last synced: 11 months ago
JSON representation
Solution to the GKS 2020 Round C problem "Stable Wall"
- Host: GitHub
- URL: https://github.com/zdimension/stablewall
- Owner: zdimension
- License: mit
- Created: 2020-06-28T08:59:49.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-07-27T02:39:51.000Z (over 5 years ago)
- Last Synced: 2025-02-04T18:52:14.239Z (about 1 year ago)
- Language: Python
- Size: 8.79 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# stablewall
Solution to the GKS 2020 Round C problem "Stable Wall"
## How it works

### Step 1
Let
be the set of letters and
the set of directed dependencies between letters.
A dependency
is *redundant* (noted
) iff
.
Let
where
refers to the "ground".
Let
. In this case,
. In this case, there were no *redundant* dependencies. The dependency
was added to allow easier computation of the node degrees.
Let
denote the directed graph
.
The input is valid iff
is acyclic.

The number of valid solutions is obtained using the expression
.
### Step 2
Let
denote the transitive closure of
. We have
. Let \notin{R^{+}})
The valid solutions
are the permutations of
ordered under
.
In other words, we have
(note that here
is an ordered tuple and not a set).
### Step 3: Preprocessing
Let
which returns the set of all nodes reachable from the specified node, i.e. all supporting letters for a specified letter with
(this can be done using DFS or recursive graph traversal), here we have
|
|
|
| ------------- | ------------- |
|
|
|
|
|
|
|
|
|
|
|
|
### Step 4: Processing
1. While there are letters yet to be added to the answer:
1. Find the first one whose supporting letters are all already present, and add it.
2. If no such letter is found, halt. There is a cycle in the directed graph, which means two letters are codependent. Thus, there is no solution.