//  [typescript]
const log = console.log;

const createScanFunctions = (input: string) => {
  const str = input.trim();
  const len = str.length;
  let index = 0;

  const scan = () => {
    const startIndex = index;

    while (index < len) {
      const char = str[index];

      if (char === " " || char === "\n")
        return str.substring(startIndex, index++);

      index++;
    }

    return str.substr(startIndex);
  };

  const scanInt = () => parseInt(scan());

  return { scan, scanInt };
};

// ----

const createArrayOfNumberArrays = (length: number) => {
  const array = new Array<number[]>(length);
  for (let i = 0; i < length; i++) array[i] = [];

  return array;
};

const isEven = (n: number) => (n & 1) === 0;

// ----

const createDepthFirstSearchFunction = <T>(
  firstId: number,
  visitNeighbors: (id: number, endVisit: (id: number) => void) => null | T,
  fullSearch: boolean = false
) => {
  const recentVisitedStack: number[] = [];
  const endVisit = (id: number) => recentVisitedStack.push(id);
  endVisit(firstId);

  const processRecentVisitedVertex = (): null | T => {
    const recentVertexId = recentVisitedStack.pop() as number; // checked before calling this function

    return visitNeighbors(recentVertexId, endVisit);
  };

  if (fullSearch) {
    return () => {
      while (recentVisitedStack.length) processRecentVisitedVertex();
    };
  }

  return () => {
    while (recentVisitedStack.length) {
      const result = processRecentVisitedVertex();

      if (result !== null) return result;
    }

    return null;
  };
};

// ----

function Main(input: string): void {
  const { scanInt } = createScanFunctions(input);

  // prepare graph
  const n = scanInt();
  const neighborIdTable = createArrayOfNumberArrays(n);
  const neighborDistanceTable = createArrayOfNumberArrays(n);
  const vertexColorArray = new Array<number | undefined>(n).fill(undefined);

  function linkVertices(id: number, neighborId: number, distance: number) {
    neighborIdTable[id].push(neighborId);
    neighborDistanceTable[id].push(distance);
    neighborIdTable[neighborId].push(id);
    neighborDistanceTable[neighborId].push(distance);
  }

  // read edges data
  const edgeCount = n - 1;

  for (let i = 0; i < edgeCount; i++)
    linkVertices(scanInt() - 1, scanInt() - 1, scanInt());

  // prepare search
  const visitNeighbors = (id: number, endVisit: (id: number) => void) => {
    const neighborIdArray = neighborIdTable[id];
    const neighborDistanceArray = neighborDistanceTable[id];
    const neighborCount = neighborIdArray.length;
    const recentColor = vertexColorArray[id] as number; // unsafe

    for (let i = 0; i < neighborCount; i++) {
      const neighborId = neighborIdArray[i];

      if (vertexColorArray[neighborId] !== undefined) continue; // already visited

      vertexColorArray[neighborId] = isEven(neighborDistanceArray[i])
        ? recentColor
        : recentColor ^ 1;

      endVisit(neighborId);
    }
  };

  const visitAllVertices = createDepthFirstSearchFunction(
    0,
    visitNeighbors,
    true
  );

  // do search
  vertexColorArray[0] = 0; // visit first vertex
  visitAllVertices();

  // output
  for (const color of vertexColorArray) log(color);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));