An open API service indexing awesome lists of open source software.

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"

Awesome Lists containing this project

README

          

# stablewall
Solution to the GKS 2020 Round C problem "Stable Wall"

## How it works

![](https://i.imgur.com/Oag9yYK.png?1)

### 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.

![G](https://i.imgur.com/L2nOmiY.png?1)

The number of valid solutions is obtained using the expression .

### Step 2

Let denote the transitive closure of . We have . Let

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.