P4366 [Code+#4] Shortest Path

Background

At latitude 91° N, there is a magical country called the Penguin Kingdom. The penguins here have their own advanced civilization, known as the Penguin Civilization. Since penguins are only black and white, their mathematics is also based on binary. For example, as early as $11101001$ years ago, they had the mathematical concept of XOR. If you do not know what XOR is, please go out, turn left, and head over to [here](https://zh.wikipedia.org/wiki/%E9%80%BB%E8%BE%91%E5%BC%82%E6%88%96). Also, as early as $1000010$ years ago, their great scientist Penguin. Tu proposed concepts such as [graph](https://zh.wikipedia.org/wiki/%E5%9B%BE_%28%E6%95%B0%E5%AD%A6%29#%E6%9C%89/%E7%84%A1_%E5%90%91%E5%9B%BE) and [shortest path](https://zh.wikipedia.org/wiki/%E6%9C%80%E7%9F%AD%E8%B7%AF%E9%97%AE%E9%A2%98).

Description

There are $N$ cities in the Penguin Kingdom, numbered from $1$ to $N$. For any two cities $i$ and $j$, penguins can spend $(i~\mathrm{xor}~j) \times C$ time to travel from city $i$ to city $j$, where $C$ is a given constant. In addition, there are $M$ one-way express channels. The $i$-th express channel goes from city $F_i$ to city $T_i$, and taking this channel costs $V_i$ time. Now a penguin named Doudou from **P**enguin **K**ingdom **U**niversity is considering the minimum time needed to travel from city $A$ to city $B$.

Input Format

Read from standard input. The first line of input contains three integers $N,M,C$ $(1 \leq C \leq 100)$, representing the number of cities, the number of express channels, and the given constant $C$ mentioned in the statement. The next $M$ lines each contain three positive integers $F_i,T_i,V_i$ ($1 \leq F_i \leq N$, $1 \leq T_i \leq N, 1 \leq V_i \leq 100$), representing the start city, the end city, and the time cost of taking this channel, respectively. The last line contains two positive integers $A,B$, representing the start city and the end city chosen by Doudou.

Output Format

Output to standard output. Output one line with a single integer, the minimum time required to travel from city $A$ to city $B$.

Explanation/Hint

Sample 1 explanation. It is optimal to go directly from $1$ to $4$. Sample 2 explanation. First go from $3$ to $2$, then take the channel from $2$ to $4$, and finally go from $4$ to $6$. ![0](https://cdn.luogu.com.cn/upload/pic/16868.png) The lively and lovely problem setter left everyone the picture below. ![1](https://i.loli.net/2018/04/02/5ac1bb2333c22.jpg) Credit: https://www.luogu.org/discuss/show/38908 Translated by ChatGPT 5