luogu#P7082. [NWRRC2013] Dwarf Tower

[NWRRC2013] Dwarf Tower

题目描述

Little Vasya is playing a new game named "Dwarf Tower". In this game there are nn different items, which you can put on your dwarf character. Items are numbered from 11 to nn . Vasya wants to get the item with number 11 .

There are two ways to obtain an item:

You can buy an item. The i-th item costs cic_i money.

You can craft an item. This game supports only mm types of crafting. To craft an item, you give two particular different items and get another one as a result.

Help Vasya to spend the least amount of money to get the item number 11 .

输入格式

The first line contains two integers nn and m(1n10000,0m100000)m (1 \le n \le 10000 , 0 \le m \le 100000) - the number of different items and the number of crafting types.

The second line contains nn integers cic_i - values of the items (0ci109)(0 \le c_i \le 10^9) .

The following mm lines describe crafting types, each line contains three distinct integers ai,xi,yia_i, x_i, y_i -- aia_i is the item that can be crafted from items xix_i and $y_i (1 \le a_i, x_i, y_i \le n , a_i \ne x_i, x_i \ne y_i, y_i \ne a_i)$.

输出格式

Print a single integer -- the least amount of money to spend.

题目大意

题目描述

小Vasya 在玩一个新游戏叫做 Dwarf Tower。在这个游戏中有 nn 个不同的衣物给你的矮人。衣物从 11nn 进行编号。Vasya 想要获得编号为 11 的衣物。

现在有两种方法获得一件衣物:

  1. 你可以买它,第 ii 件物品花费 cic_i 元。

  2. 你还可以制作它,这个游戏支持 mm 中制作方法。要制作一个衣物,你需要花费两个特定的衣物。

算出 Vasya 至少需要多少钱来获得一号衣物。

输入格式

第一行输入两个整数 nn , mm (1n10000,0m100000)(1 \le n \le 10000 , 0 \le m \le 100000) 代表有 nn 种衣物和有 mm 种制作方法。

第二行输入 nn 个整数,第 ii 个整数代表 cic_i (0ci109)(0 \le c_i \le 10^9)

接下来 mm 行每行有三个整数 ai,xi,yia_i, x_i, y_i $(1 \le a_i, x_i, y_i \le n , a_i \ne x_i, x_i \ne y_i, y_i \ne a_i)$ ,aia_i 代表 aia_i 可以被 xix_iyiy_i 制作。

输出格式

一个整数,代表 Vasya 至少需要多少钱来获得一号衣物。

5 3
5 0 1 2 5
5 2 3
4 2 3
1 4 5

2

提示

Time limit: 2 s, Memory limit: 256 MB.