Clothes

A. Clothes
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.


Input

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 ().

Next line contains n integers ai (1 ≤ ai ≤ 106) — the prices of the clothing items in rubles.

Next m lines each contain a pair of space-separated integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi). Each such pair of numbers means that the ui-th and the vi-th clothing items match each other. It is guaranteed that in each pair ui and vi are distinct and all the unordered pairs (ui, vi) are different.


Output

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).


Sample test(s)
Input
3 3
1 2 3
1 2
2 3
3 1
Output
6
Input
3 2
2 3 4
2 3
2 1
Output
-1
Input
4 4
1 1 1 1
1 2
2 3
3 4
4 1
Output
-1
Note

In the first test there only are three pieces of clothing and they all match each other. Thus, there is only one way — to buy the 3 pieces of clothing; in this case he spends 6 roubles.

The second test only has three pieces of clothing as well, yet Gerald can't buy them because the first piece of clothing does not match the third one. Thus, there are no three matching pieces of clothing. The answer is -1.

In the third example there are 4 pieces of clothing, but Gerald can't buy any 3 of them simultaneously. The answer is -1.

大致题意:商店中有n件衣服,分别有n个价格,给出m组样例,分别表示每个衣服的所对应的衣服号数,问题是求能够匹配的三件衣服所需要的最少的钱数。

解决方法:直接用暴力搜索就可以求出,注意最大值的范围用无穷大oxffffff。

#include <stdio.h>
int cloth[101][101], price[101];
int main()
{
    int n, m, i, j, k, x, y, cost, min;
    while(scanf("%d%d", &n, &m)!=EOF)
    {
        cost=0; min=0xffffff;
        for(i=1; i<=n; i++)
            scanf("%d", &price[i]);
        for(i=0; i<m; i++)
        {
             scanf("%d%d", &x, &y);
             cloth[x][y]=cloth[y][x]=1;
        }

            for(i=1; i<=n; i++)
            {
                for(j=1; j<=n; j++)
                {
                    if(i!=j)
                    {
                        for(k=1; k<=n; k++)
                        {
                            if(i!=k&&k!=j)
                            {
                               if(cloth[i][j]&&cloth[j][k]==1&&cloth[k][i]==1)
                               {
                                   cost=price[i]+price[j]+price[k];
                                   if(cost<min)
                                    min=cost;
                               }
                            }
                        }
                    }
                }
            }

        if(min==0xffffff)
            printf("-1\n");
        else
            printf("%d\n", min);
    }
    return 0;
}


进入互联网新媒体时代,“股吧”作为一类专门针对上市公司的社交媒介,已经成为中小投资者分享投资经验和发表对公司运营意见的重要平台,股吧舆论作为投资者情绪的反映,直接影响股票的市场表现。 一、上市公司股吧舆论数据的介绍 “股吧”作为新兴社交媒体代表,本身并不提供信息,仅提供多方交互平台,其将个体间的实时交流和回应形成公众关注和舆论;因此,股吧舆论数据可以帮助研究人员深入分析网络舆论与企业表现之间的关系,并为投资者提供情绪波动的参考依据。 本分享数据年份为2008年到2023年,数据来源于东方财富网股吧,涉及A股上市公司的讨论情况,涵盖了股吧发帖数量、阅读量、评论次数等多个维度。 二、数据指标 指标名称 描述 计算方法 Post 股吧发帖数量 上市公司当年度东方财富网股吧发帖数量之和加1并取自然对数 Positive 正面帖子数量 上市公司当年度东方财富网股吧正面帖子数量之和加1并取自然对数 Negative 负面帖子数量 上市公司当年度东方财富网股吧负面帖子数量之和加1并取自然对数 Neutral 中性帖子数量 上市公司当年度东方财富网股吧中性帖子数量之和加1并取自然对数 Read 股吧阅读量 上市公司当年度东方财富网股吧被阅读次数之和加1并取自然对数 Comment 股吧评论量 上市公司当年度东方财富网股吧被跟帖评论次数之和加1并取自然对数 三、数据说明 本数据集的统计范围为A股上市公司,数据分为三个版本: 未剔除金融STPT未缩尾版本 已剔除金融STPT未缩尾版本 已剔除金融STPT已缩尾版本 数据提供格式:Excel、dta格式。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值