题目连接:
Description
Little Vasya is playing a new game named “Dwarf Tower”. In this game there are n different items,
which you can put on your dwarf character. Items are numbered from 1 to n. Vasya wants to get theitem with number 1.There are two ways to obtain an item:• You can buy an item. The i-th item costs ci money.• You can craft an item. This game supports only m types of crafting. To craft an item, you givetwo particular different items and get another one as a result.Help Vasya to spend the least amount of money to get the item number 1.Input
The first line of input contains two integers n and m (1 ≤ n ≤ 10 000; 0 ≤ m ≤ 100 000) — the number
of different items and the number of crafting types.The second line contains n integers ci — values of the items (0 ≤ ci ≤ 109).The following m lines describe crafting types, each line contains three distinct integers ai, xi, yi — ai is the item that can be crafted from items xi and yi (1 ≤ ai , xi , yi ≤ n; ai ̸= xi ; xi ̸= yi ; yi ̸= ai).Output
The output should contain a single integer — the least amount of money to spend.
Sample Input
5 3
5 0 1 2 55 2 34 2 31 4 5Sample Output
2
题意:
对与一个物品,你可以选择购买获得,但是要花费ci , 或者是通过 xi yi 合成。
要你用最小的花费得到物品1.
题解:
我们对于每一个物品都应该花最小的花费的到。 a可以通过x, y合成。那么从x去到a的费用就是 c[y] 。(因为你已经跑到了x点,表示你已经有了x了)。
在建一个大原点 0, 0到每个点的费用为c[i] 。然后用0这里跑一次Dij 。这样你就可以得到了获得物品i 的最小花费。
在跑一下m次合成,找到最小的花费。
1 #include2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include