hdu3311
#include <bits/stdc++.h> using namespace std; #define maxn 10000 #define INF 6e8 bool inq[2000]; int dp[1000][2000],v[2000]; struct re{ int a,b,c; }a[maxn]; int l,n,m,p,head[2000],dis[2000][2000]; void arr(int x,int y,int z) { a[++l].a=head[x]; a[l].b=y; a[l].c=z; head[x]=l; } void spfa() { queue<int> q; for (int s=0;s<=n+m;s++) { for (int j=0;j<=n+m;j++) dis[s][j]=INF; dis[s][s]=0; q.push(s); inq[s]=1; while (!q.empty()) { int x=q.front(); q.pop(); int u=head[x]; while (u) { int v=a[u].b; if (dis[s][v]>dis[s][x]+a[u].c) { dis[s][v]=dis[s][x]+a[u].c; if (!inq[v]) { q.push(v); inq[v]=1; } } u=a[u].a; } inq[x]=0; } } } void get_ans() { for (int i=1;i<=(1<<n)-1;i++) for (int j=0;j<=n+m;j++) dp[i][j]=INF; for (int i=1;i<=n;i++) dp[1<<(i-1)][i]=0; for (int i=1;i<=(1<<n)-1;i++) { for (int j=0;j<=n+m;j++) { for (int k=i;k;k=(k-1)&i) if (dp[i][j]>dp[k][j]+dp[i^k][j]) dp[i][j]=dp[k][j]+dp[i^k][j]; } for (int k1=0;k1<=n+m;k1++) for (int k2=0;k2<=n+m;k2++) if (dp[i][k1]>dp[i][k2]+dis[k2][k1]) dp[i][k1]=dp[i][k2]+dis[k2][k1]; } } int main() { freopen("noip.in","r",stdin); std::ios::sync_with_stdio(false); while (cin>>n>>m>>p&&n>0) { l=0;memset(head,0,sizeof(head)); for (int i=1;i<=m+n;i++) { cin>>v[i]; arr(i,0,v[i]); } int c,d,e; for (int i=1;i<=p;i++) { cin>>c>>d>>e; arr(c,d,e); arr(d,c,e); } spfa(); get_ans(); cout<<dp[(1<<n)-1][0]<<endl; } return 0; }