#P9377. [THUPC 2023 决赛] 百合

[THUPC 2023 决赛] 百合

Background

Lilies cannot bloom on grapevines.

Problem Description

You land on a huge grape trellis. There are 2k2^k lilies and mm grapevines on it. The lilies are labeled with integers from 00 to 2k12^k-1. The ii-th grapevine connects lilies xix_i and yiy_i.

You can spend cic_i time to travel along the ii-th grapevine, i.e., from xix_i to yiy_i or vice versa. You can also spend aka_k time to teleport from xx to yy, where xx and yy are any two lilies, and kk is the number of differing bits in their binary representations. For example, the binary representation of 33 is 011011, and the binary representation of 55 is 101101. They differ in two bits, so teleporting from 33 to 55 costs a2a_2 time.

Suppose you land exactly on the lily labeled ss. Find the shortest time needed to travel from ss to every lily.

Input Format

The first line contains three positive integers k,m,sk, m, s, as described above.

The second line contains kk non-negative integers aia_i, representing the time cost of teleportation.

Lines 33 to (m+2)(m+2) each contain three non-negative integers xi,yi,cix_i, y_i, c_i.

Output Format

Output one line with 2k2^k numbers DiD_i (0i2k10 \leq i \leq 2^k-1), separated by spaces, where DiD_i is the shortest time from ss to ii.

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, 1k171 \le k \leq 17, 1m2×1051 \le m \leq 2 \times 10^5, 0s,xi,yi2k10 \leq s, x_i, y_i \leq 2^k - 1, 0ai,ci23010 \le a_i, c_i \leq 2^{30} - 1.

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