Editorial for COI '14 #2 Kovanice


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Let's first imagine there aren't any weighings in which both sides are equal. We will construct a graph where each weighing a < b creates an edge a \to b. The constructed graph is a directed acyclic graph (DAG), because if we had cycles, that would mean that the test data isn't consistent.

It is clear that this graph cannot have a chain longer than N because that would mean that there are more than N types of coins. The coins located on the chain of length N have their weight determined unambiguously and it is known that the first coin in the chain is K1, the second K2 and so on until the N^\text{th} coin which is KN. The coins not located in any chain of length N cannot have their weight unambiguously determined because that means there are more types of coins than the number of coins in the chain, and therefore there are more possible layouts satisfying the conditions from the chain.

Now it is also possible to process the weighings in which both sides are equal. All coins of equal weight can be combined in one node and run the previously described algorithm on this graph. It is necessary to remember which coins are in which node so we can output the result for each of them.


Comments

There are no comments at the moment.