Orienting Molecular Bonds
InterviewTime limit1sMemory limit64 MB
Direct every tree edge from the endpoint at even distance from node 1 to the one at odd distance.
Problem
Scientists in a chemical lab in Croatia study the chemical bonds between molecules. Their current subject is a group of molecules of the compound nitro hydrogen laminate.
The compound consists of molecules held together by covalent bonds, and every molecule is tied to the rest directly or indirectly, so the bonds form one connected structure.
The scientists want to turn every covalent bond into a directed bond. The new compound is unstable, so each molecule emits a large number of impulses that travel to other molecules along the directed bonds. An impulse can cross a bond only in the direction of that bond.

The instability of the compound is the largest number of bonds a single impulse can cross on its travel. The scientists want to orient the bonds so that the compound is as stable as possible, that is, so that the instability is minimal.
Determine the direction of every covalent bond.
Input
The first line contains the number of molecules ().
Each of the next lines contains two integers and (), meaning that molecules and are joined by a covalent bond. The bonds always form a tree.
Output
Print lines. Line gives the direction of the -th bond of the input: print 1 if the bond is directed from to , and 0 if it is directed from to .
Several orientations reach the minimal instability, so only the one fixed by the following rule is accepted. Measure the distance from molecule 1 to each molecule as the number of bonds on the way, then direct every bond from its endpoint at even distance to its endpoint at odd distance. The two endpoints of a bond differ in distance by exactly 1, so the direction is determined.