logo AlgoBeat OnlineJudge
登录 注册

#206226. [NWRRC 2013] Dwarf Tower

内存限制:256 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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

There are two ways to obtain an item:

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

You can craft an item. This game supports only 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 .

输入格式

The first line contains two integers and the number of different items and the number of crafting types.

The second line contains integers values of the items .

The following lines describe crafting types, each line contains three distinct integers -- is the item that can be crafted from items and .

输出格式

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

样例

样例输入 1

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

样例输出 1

2

数据范围与提示

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