#include<cstdio>#include<algorithm>#define maxn 305usingnamespace std;struct node{int u, v, l;}e[maxn * maxn <<2];int tot =0;voidaddedge(int u,int v,int l){e[++tot]=(node){u, v, l};}boolcmp(const node &a,const node &b){return a.l < b.l;}int n, f[maxn];intgetf(int x){return(f[x]== x)? x : f[x]=getf(f[x]);}intKrusual(){sort(e +1, e + tot +1, cmp);for(int i =1; i <= n; i++) f[i]= i;int res =0;for(int i =1; i <= tot; i++){if(getf(e[i].u)!=getf(e[i].v)){
f[getf(e[i].u)]=getf(e[i].v);
res += e[i].l;}}return res;}intmain(){scanf("%d",&n);for(int x, i =1; i <= n; i++){scanf("%d",&x);addedge(0, i, x);}for(int x, i =1; i <= n; i++)for(int j =1; j <= n; j++){scanf("%d",&x);addedge(i, j, x);}printf("%d\n",Krusual());return0;}