Under construction

Still being built. Things may change

Orienting Molecular Bonds

Interview

Time limit1sMemory limit64 MB

Summary
Direct every tree edge from the endpoint at even distance from node 1 to the one at odd distance.
Level

Easy3 of 10

Topics
BFS, Tree
Solved
No attempts yet

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 NN molecules held together by N−1N-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.

Input

The first line contains the number of molecules NN (2≤N≤100 0002 \le N \le 100\,000).

Each of the next N−1N-1 lines contains two integers aia_i and bib_i (1≤ai,bi≤N1 \le a_i, b_i \le N), meaning that molecules aia_i and bib_i are joined by a covalent bond. The bonds always form a tree.

Output

Print N−1N-1 lines. Line ii gives the direction of the ii-th bond of the input: print 1 if the bond is directed from aia_i to bib_i, and 0 if it is directed from bib_i to aia_i.

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.

Examples2

  1. Example 1

    Input
    3
    1 2
    2 3
    
    Expected output
    1
    0
    
  2. Example 2

    Input
    4
    2 1
    1 3
    4 1
    
    Expected output
    0
    1
    0