/**
 *    author:  orzvanh14 (  )
 *    created: 23.12.2022 10:08:02
 *    too lazy to update time
**/
// i wants to take ioi
//binhtinhtutinkhongcaycunhungmotkhikhongcontutinnualatuyetvong
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define nn "\n"
#define pi pair<int, int>
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define eb emplace_back
#define pb push_back
#define TASK " "

#define ms(a, x) memset(a, x, sizeof(a))
#define all(a) a.begin(), a.end()
#define All(a, n) a + 1, a + 1 + n

#define LOG 19


const int INF = 1e18;
const int mod = 1e9+7;
const int N = 5e2  + 5;
int MOD = 998244353;
int bit[200000];
struct node{
	int kc, u, hk;
	bool operator<(const node& other) const {
        return kc > other.kc;
    }
};
struct edge{
	int u, v, w;
	friend bool operator < ( edge a, edge b){
		return a.w < b.w;
	}
};
vector<edge> adj;
int n;
int lab[N];
int a[N], b[N][N];
int get(int v){
	if(lab[v] < 0) return v;
	return lab[v] = get(lab[v]);
}
bool union_sets(int a, int b){
	a = get(a);
	b = get(b);
	if(a != b){
		if(lab[a] > lab[b]) swap(a, b);
		lab[a] += lab[b];
		lab[b] = a;
		return true;
	}
	else return false;

}
void nhap(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        adj.push_back({0, i, a[i]});
    }
    for(int i = 1; i <= n;i++){
        for(int j = 1; j <= n ; j++){
            cin >> b[i][j];
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = i + 1; j <= n; j++){
            adj.push_back({i, j, b[i][j]});
        }
    }
}
void solve(){
	memset(lab, -1, sizeof(lab));
	sort(adj.begin(), adj.end());
	int ans = 0;
	for(auto edges : adj){
		if(union_sets( edges.u, edges.v ) ) ans += edges.w;
	}
	cout << ans << nn;
}
signed main() {
	// freopen("piggyback.in", "r", stdin);
	// freopen("piggyback.out", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    nhap();
    solve();
	return 0;

}