300535: CF102A. Clothes
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Clothes
题意翻译
有 $n$ 件服装,$m$ 组匹配关系,每件服装的价格为 $a_i$。 请找出三件两两匹配的服装,求出最小的价格之和。如果找不到这样的三件服装,输出 `-1`。 $3 \le n \le 100$,$0 \le m \le \frac{n(n-1)}{2}$,$1 \le a_i \le 10^6$。题目描述
A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap. Overall the shop sells $ n $ clothing items, and exactly $ m $ pairs of clothing items match. Each item has its price, represented by an integer number of rubles. Gerald wants to buy three clothing items so that they matched each other. Besides, he wants to spend as little money as possible. Find the least possible sum he can spend.输入输出格式
输入格式
The first input file line contains integers $ n $ and $ m $ — the total number of clothing items in the shop and the total number of matching pairs of clothing items (![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF102A/109c01c4816fa11a9f937be6e68f6e85187ffea5.png)). Next line contains $ n $ integers $ a_{i} $ ( $ 1<=a_{i}<=10^{6} $ ) — the prices of the clothing items in rubles. Next $ m $ lines each contain a pair of space-separated integers $ u_{i} $ and $ v_{i} $ ( $ 1<=u_{i},v_{i}<=n,u_{i}≠v_{i} $ ). Each such pair of numbers means that the $ u_{i} $ -th and the $ v_{i} $ -th clothing items match each other. It is guaranteed that in each pair $ u_{i} $ and $ v_{i} $ are distinct and all the unordered pairs $ (u_{i},v_{i}) $ are different.
输出格式
Print the only number — the least possible sum in rubles that Gerald will have to pay in the shop. If the shop has no three clothing items that would match each other, print "-1" (without the quotes).
输入输出样例
输入样例 #1
3 3
1 2 3
1 2
2 3
3 1
输出样例 #1
6
输入样例 #2
3 2
2 3 4
2 3
2 1
输出样例 #2
-1
输入样例 #3
4 4
1 1 1 1
1 2
2 3
3 4
4 1
输出样例 #3
-1