Problem A
Reactivity Series

During his physics research, the Ph.D. candidate Ulf invented some new metals as the existing ones were not good enough. He is now investigating the properties of the new metals, and is interested in knowing how reactive they are, so that he won’t blow his house up while mixing them with water.
He wants to order the metals by reactivity into a so-called reactivity series, where the metal with the highest reactivity comes first, and lowest reactivity comes last. Normally, Ulf (who is also proficient in computer science) would make an optimal scheme of measurements such that he has to make as few measurements as possible to determine such a series. Unfortunately, having invented entirely new substances, he was eager to begin experimenting, and randomly took pairs of elements and compared their reactivity.
Ulf’s experiments consisted of taking two different metals,
and testing which one had the highest reactivity. You may
assume Ulf never makes mistakes in his experiments, and that
the reactivity is distinct for all elements (i.e. for any pair
of metals, one will always be the more reactive one). This
relation is such that if metal
Before continuing his experiments, he is wondering whether the measurements he already has are enough to determine a unique reactivity series of all his metals.
Input
The first line will consist of two integers
Output
Output consists of
Sample Input 1 | Sample Output 1 |
---|---|
2 1 0 1 |
0 1 |
Sample Input 2 | Sample Output 2 |
---|---|
4 4 0 1 0 2 2 3 1 3 |
back to the lab |