http://codeforces.com/contest/102

A

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define lson l,mid,rt<<1
 4 #define rson mid+1,r,rt<<1|1
 5 #define sqr(x) ((x)*(x))
 6 #define pb push_back
 7 #define eb emplace_back
 8 #define maxn 13000005
 9 #define eps 1e-8
10 #define pi acos(-1.0)
11 #define rep(k,i,j) for(int k=i;k<j;k++)
12 typedef long long ll;
13 typedef pair<int,int> pii;
14 typedef pair<long long,int>pli;
15 typedef pair<char,int> pci;
16 typedef pair<pair<int,string>,pii> ppp;
17 typedef unsigned long long ull;
18 const long long MOD=1e9+7;
19 /*#ifndef ONLINE_JUDGE
20         freopen("1.txt","r",stdin);
21 #endif */
22 
23 int a[105][105];
24 int v[105];
25 
26 int main(){
27     #ifndef ONLINE_JUDGE
28      //   freopen("1.txt","r",stdin);
29     #endif
30     std::ios::sync_with_stdio(false);
31     int n,m;
32     cin>>n>>m;
33     for(int i=1;i<=n;i++) cin>>v[i];
34     int uu,vv;
35     for(int i=1;i<=m;i++){
36         cin>>uu>>vv;
37         a[uu][vv]=a[vv][uu]=1;
38     }
39     int ans=0x3f3f3f3f;
40     for(int i=1;i<=n;i++){
41         for(int j=1;j<=n;j++){
42             for(int k=1;k<=n;k++){
43                 if(i==j||j==k||k==i) continue;
44                 if(a[i][j]==a[j][k]&&a[j][k]==a[k][i]&&a[k][i]==1){
45 
46                     ans=min(ans,v[i]+v[j]+v[k]);
47                 }
48             }
49         }
50     }
51     if(ans==0x3f3f3f3f) cout<<-1;
52     else
53     cout<<ans<<endl;
54 }
View Code

相关文章: