#P9377. Grape Arbor Escape

    ID: 22529 Type: Default 1000ms 256MiB

Grape Arbor Escape

Grape Arbor Escape

You find yourself stranded on a massive grape arbor. There are exactly 2k2^k lilies, numbered from 00 to 2k12^k-1, and mm grape vines. The ii-th grape vine connects the lilies numbered xix_i and yiy_i.

You can traverse the ii-th grape vine in either direction at a cost of cic_i. In addition, you have the ability to teleport between any two lilies xx and yy at a cost of ada_{d}, where dd is the number of bits in which the binary representations of xx and yy differ, i.e. $$d = \mathrm{popcount}(x \oplus y).$$ For example, the binary representations of 33 (which is 011011) and 55 (which is 101101) differ in two positions, so teleporting between them costs a2a_2.

Assuming you start on the lily numbered ss, compute the minimum time required to reach every lily.

inputFormat

The input consists of several lines. The first line contains three integers kk, mm, and ss, where n=2kn=2^k is the total number of lilies. Each of the next mm lines contains three integers xix_i, yiy_i, and cic_i, describing a grape vine connecting lilies xix_i and yiy_i with cost cic_i. The last line contains k+1k+1 integers: a0,a1,,aka_0, a_1, \dots, a_k, representing the teleportation costs according to the number of different bits.

outputFormat

Output a single line with nn space-separated integers, where the ii-th integer is the minimum time to reach the lily numbered ii from lily ss.

sample

2 2 0
0 1 3
1 2 2
0 1 5
0 1 1 2