Direct every tree edge from the endpoint at even distance from node 1 to the one at odd distance.
Easy3BFSTreeInterviewNo attempts yetTime limit1sMemory limit64 MBScientists 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 N molecules held together by N−1 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.
The first line contains the number of molecules N (2≤N≤100000).
Each of the next N−1 lines contains two integers ai and bi (1≤ai,bi≤N), meaning that molecules ai and bi are joined by a covalent bond. The bonds always form a tree.
Print N−1 lines. Line i gives the direction of the i-th bond of the input: print 1 if the bond is directed from ai to bi, and 0 if it is directed from bi to ai.
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.