아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

XorTree

시간 제한2초메모리 제한256 MB

요약
한 번의 연산으로 트리의 한 경로에 속한 모든 간선에 같은 값을 XOR할 수 있을 때, 모든 간선 값을 0으로 만드는 최소 연산 횟수를 구한다.
난이도

보통10점 중 7점

유형
트리, DFS, 그리디, 비트 연산
정답자
아직 제출이 없습니다

문제

You are given a tree with NN vertices. The vertices are numbered 00 through N−1N-1, and the edges are numbered 11 through N−1N-1. Edge ii connects vertex x_ix\_i and y_iy\_i, and has a value a_ia\_i. You can perform the following operation any number of times: choose a simple path and a non-negative integer xx, then for each edge ee that belongs to the path, change a_ea\_e by executing a_e:=a_e⊕xa\_e := a\_e \oplus x (⊕\oplus denotes XORXOR).

Your objective is to have a_e=0a\_e = 0 for all edges ee. Find the minimum number of operations required to achieve it.

입력

Input is given in the following format:

NN

x_1x\_1 y_1y\_1 a_1a\_1

x_2x\_2 y_2y\_2 a_2a\_2

…\ldots

x_N−1x\_{N-1} y_N−1y\_{N-1} a_N−1a\_{N-1}

출력

Find the minimum number of operations required to achieve the objective.

제한

2≤N≤1052 \le N \le 10^5, 0≤x_i,y_i≤N−10 \le x\_i,y\_i \le N-1, 0≤a_i≤150 \le a\_i \le 15. The given graph is a tree, all input values are integers.

힌트

In Sample 1, the objective can be achieved in three operations, as follows: first, choose the path connecting Vertex 1,21, 2, and x=1x = 1, then, choose the path connecting Vertex 2,32, 3, and x=2x = 2; lastly, choose the path connecting Vertex 0,40, 4, and x=4x = 4.

예제2

  1. 예제 1

    입력
    5
    0 1 1
    0 2 3
    0 3 6
    3 4 4
    
    예상 출력
    3
    
  2. 예제 2

    입력
    2
    1 0 0
    
    예상 출력
    0