// Arup Guha
// 1/24/2023
// Solution to Croatian Olympiad Problem: Molekule
// https://open.kattis.com/problems/molekule

import java.util.*;
import java.io.*;

public class molekule {

	public static int n;
	public static ArrayList<Integer>[] g;
	public static int[] depth;
	public static int[][] eList;
	
	public static void main(String[] args) throws Exception {
	
		BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
		n = Integer.parseInt(stdin.readLine());
		
		// Creates empty graph.
		g = new ArrayList[n];
		for (int i=0; i<n; i++)
			g[i] = new ArrayList<Integer>();
		
		// Set up these arrays.
		depth = new int[n];
		Arrays.fill(depth, -1);
		eList = new int[n][2];
		
		// Add edges.
		for (int i=0; i<n-1; i++) {
			StringTokenizer tok = new StringTokenizer(stdin.readLine());
			eList[i][0] = Integer.parseInt(tok.nextToken())-1;
			eList[i][1] = Integer.parseInt(tok.nextToken())-1;
			g[eList[i][0]].add(eList[i][1]);
			g[eList[i][1]].add(eList[i][0]);
		}
		
		// Root tree at 0, second parameter is parent.
		depth[0] = 0;
		rootTree(0, -1);
		
		StringBuffer sb = new StringBuffer();
		for (int i=0; i<n-1; i++) {
			if (depth[eList[i][0]]%2 == 0)
				sb.append("0\n");
			else
				sb.append("1\n");
		}
		
		// Let's output our result!
		System.out.print(sb);
	}
	
	public static void rootTree(int node, int par) {
	
		// Loops through each kid.
		for (Integer kid: g[node]) {
		
			// Not an actual kid.
			if (par == kid) continue;
			
			// Mark this depth and recurse.
			depth[kid] = depth[node] + 1;
			rootTree(kid, node);
		}
	
	}
}