Problem Q
Molekule
Scientists in a chemical lab in Croatia have been studying
the chemical bonds between different molecules. They have a
special interest in a group of molecules of the chemical
compound nitro hydrogen laminate. The compound consists of
The scientists want to modify the compound in a way that all the covalent bonds are transformed into directed covalent bonds. Because of the instability of the newly created compound, each molecule will have a large number of impulses coming out of it and travelling to other molecules using the directed bonds. An impulse can travel using the directed covalent bond only in the direction of the bond itself.
![\includegraphics[width=.7\textwidth ]{picture.pdf}](/problems/molekule/file/statement/en/img-0001.png)
The instability of the compound is defined as the largest possible number of bonds a single impulse can use to travel. The scientists want to direct the compound’s covalent bonds in a way that the newly created compound is as stable as possible. In other words, their goal is to create a compound with the minimal longest path an impulse can take during its travel.
Help the scientists determine the direction of each covalent bond in the compound.
Input
The first line of input contains the integer
Output
Output
Sample Input 1 | Sample Output 1 |
---|---|
3 1 2 2 3 |
0 1 |
Sample Input 2 | Sample Output 2 |
---|---|
4 2 1 1 3 4 1 |
1 0 1 |