using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
using static System.Console;

namespace D_ABC126
{
    class MainClass
    {

        static int[] s;


        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            var tolist = new List<List<int>>(s[0]);
            var costlist = new List<List<int>>(s[0]);
            for(int i = 0;i<s[0];i++){
                tolist.Add(new List<int>());
                costlist.Add(new List<int>());
            }
            for (int i = 0; i < s[0] - 1; i++)
            {
                int[] abw = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
                int a = abw[0] - 1;
                int b = abw[1] - 1;
                int w = abw[2];
                /*
                if (tolist[a] == null)
                {
                    tolist[a] = new List<int>();
                    costlist[a] = new List<int>();
                }
                if (tolist[b] == null)
                {
                    tolist[b] = new List<int>();
                    costlist[b] = new List<int>();
                }
                */

                tolist[a].Add(b);
                costlist[a].Add(w);
                tolist[b].Add(a);
                costlist[b].Add(w);
            }
            int[] ans = new int[s[0]];
            ans[0] = 0;
            for(int i =1;i<s[0];i++){
                ans[i]  =-1;
            }

            Queue<int> q = new Queue<int>();
            q.Enqueue(0);
            while(q.Any()){
                int now = q.Dequeue();
                for(int i=0;i<tolist[now].Count;i++){
                    int next = tolist[now][i];
                    if(ans[next] ==-1){
                        if(costlist[now][i]%2==0){
                            ans[next]=ans[now];
                        }else{
                            if(ans[now]==0){
                                ans[next] = 1;
                            }else{
                                ans[next]=0;
                            }
                        }
                        q.Enqueue(next);
                    }
                }
            }

            foreach(int item in ans){
                Console.WriteLine(item);
            }




        }
    }


    class UnionFind
    {
        public List<int> Parent;
        public UnionFind(int n)
        {
            //親の番号をそれぞれ格納する。自分が親なら、-(サイズ)
            this.Parent = Enumerable.Repeat(-1, n).ToList();
        }

        public int Size(int a)
        {
            if (Parent[a] < 0) return -Parent[a];
            else return -Parent[Root(a)];
        }

        public int Root(int a)
        {
            if (Parent[a] < 0) return a;
            else
            {
                int root = Root(Parent[a]);
                Parent[a] = root;
                return root;
            }
        }

        public bool Connect(int a, int b)
        {
            a = Root(a);
            b = Root(b);
            if (a == b) return false;
            else
            {
                //a > bにする
                if (a < b)
                {
                    int tmp = a;
                    a = b;
                    b = tmp;
                }
                //bの親をaにして、aのsizeにbのぶんを足す
                Parent[a] += Parent[b];
                Parent[b] = a;
                return true;
            }
        }
    }
}


Measured memory_bytes: 37372