#P9377. Grape Arbor Escape
Grape Arbor Escape
Grape Arbor Escape
You find yourself stranded on a massive grape arbor. There are exactly lilies, numbered from to , and grape vines. The -th grape vine connects the lilies numbered and .
You can traverse the -th grape vine in either direction at a cost of . In addition, you have the ability to teleport between any two lilies and at a cost of , where is the number of bits in which the binary representations of and differ, i.e. $$d = \mathrm{popcount}(x \oplus y).$$ For example, the binary representations of (which is ) and (which is ) differ in two positions, so teleporting between them costs .
Assuming you start on the lily numbered , compute the minimum time required to reach every lily.
inputFormat
The input consists of several lines. The first line contains three integers , , and , where is the total number of lilies. Each of the next lines contains three integers , , and , describing a grape vine connecting lilies and with cost . The last line contains integers: , representing the teleportation costs according to the number of different bits.
outputFormat
Output a single line with space-separated integers, where the -th integer is the minimum time to reach the lily numbered from lily .
sample
2 2 0
0 1 3
1 2 2
0 1 5
0 1 1 2