#P9377. [THUPC 2023 决赛] 百合
[THUPC 2023 决赛] 百合
Background
Lilies cannot bloom on grapevines.
Problem Description
You land on a huge grape trellis. There are lilies and grapevines on it. The lilies are labeled with integers from to . The -th grapevine connects lilies and .
You can spend time to travel along the -th grapevine, i.e., from to or vice versa. You can also spend time to teleport from to , where and are any two lilies, and is the number of differing bits in their binary representations. For example, the binary representation of is , and the binary representation of is . They differ in two bits, so teleporting from to costs time.
Suppose you land exactly on the lily labeled . Find the shortest time needed to travel from to every lily.
Input Format
The first line contains three positive integers , as described above.
The second line contains non-negative integers , representing the time cost of teleportation.
Lines to each contain three non-negative integers .
Output Format
Output one line with numbers (), separated by spaces, where is the shortest time from to .
3 6 2
17 14 11
0 2 3
4 2 9
2 2 1
2 2 6
7 0 5
4 2 9
3 14 0 17 9 11 17 8
Hint
Constraints
For all testdata, , , , .
Source
From the 2023 Tsinghua University Student Algorithmic Contest and Intercollegiate Invitational Programming Contest (THUPC2023) Finals.
Resources such as editorials can be found at https://github.com/THUSAAC/THUPC2023.
Translated by ChatGPT 5