[NOIP Simulation Test]: little odd warehouse (Warehouse) (tree DP)

Topic background

Small Odd mine too much, it is ready to build a warehouse in ore meow galaxy. It's so silent that meow galaxy cargo ship engine still stuck in the era of Spring!


Title Description

Meow galaxies $ n $ planets, stars and planets route between the formation of a tree.
$ $ A planet from planet to spend $ b $ $ [dis (a, b) \ Xor \ M] $ seconds. ($ Dis (a, b) $ denotes the length of the route between $ ab $, $ Xor $ bits in an exclusive OR operation)
in order to the warehouse location, small curious to see, planet $ i (1 \ leqslant i \ leqslant n ) $ to all the other planets of time and cost.


Input Format

The first line contains two positive integers $ n $, $ M $.
Next, $ n-1 $ lines, each positive integers $ 3 $ $ a, b, c $, represents the length route between $ a $, $ b $ to $ c $.


Output Format

$ $ N-rows, each row an integer that represents $ I $ planet all of the time spent and other planets.


Sample

Sample input:

4 0
1 2 1
1 3 2
1 4 3

Sample output:

6
8
10
12


Data range and tips

To ensure that the answer does not exceed $ 2 \ times {10} ^ 9 $.

Guess you like

Origin www.cnblogs.com/wzc521/p/11421752.html