'use strict'

class Node {
  constructor(nodeName, value) {
    this.name = nodeName;
    this.value = value;
    this.color = 0;
    this.count = 1;
    this.childrenArray = [];
    this.index = [nodeName];
    this.colorIndex = [0];
    this.parent = null;
  }

  addChild(childNode) {
    this.childrenArray.push(childNode);
    childNode.parent = this;
    childNode.value += this.calcRootValue();
    childNode.color = childNode.value % 2;
    childNode.colorIndex = [childNode.color];
    this.inclementParent(childNode);
  }

  calcRootValue() {
    return this.parent != undefined && this.parent != null ? this.value + this.parent.calcRootValue() : this.value ;
  }

  inclementParent(childNode) {
    this.count++;
    this.index.push(childNode.name);
    this.colorIndex.push(childNode.color);
    if(this.parent != undefined && this.parent != null){
      this.parent.inclementParent(childNode);
    }
  }

  indexOf(value) {
    
    if(value == this.name){
      return this
    }
    else {
      for(let i=0;i<this.childrenArray.length;i++){
        let tmpNode = this.childrenArray[i].indexOf(value);
        if(tmpNode != undefined && tmpNode != null){
           return tmpNode
        }
      }
    }
    return null;
  }
  returnColorArray() {
    let result =(new Array(this.count)).fill(0);
    
    return result;
  }
}


function Main(input) {
  input = input.split('\n');
  let N = input.shift();
  let tree =null;
  

  while (tree == null || tree.count < N) {
    if(tree == null){
      let tmp = input.shift();
      let array = tmp.split(' ');
      tree = new Node(array[0], 0);
      tree.addChild(new Node(array[1], parseInt(array[2])));
    } else {
      for (let i=0;i<input.length;i++) {
        let array = input[i].split(' ')
        let leftIndex = tree.indexOf(array[0]);
        let rightIndex = tree.indexOf(array[1]);
        if(leftIndex != null){
          leftIndex.addChild(new Node(array[1], parseInt(array[2])));
          input.splice(i,1);
        } else if (rightIndex != null) {
          rightIndex.addChild(new Node(array[0], parseInt(array[2])));
          input.splice(i,1);
        }
      }
    }
  }
  for(let i=0;i<N;i++){
    console.log(tree.colorIndex[i]);
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

