# include # include # include # include # include # include # include # include # include # include # include # include # include # include # include #include #include #include #include #include using namespace std; typedef long long int ll; const int N = 1000000; const int mod = 1000000007; const int INF = 1 << 30; #define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i) #define ALL(x) x.begin(),x.end() #define pp pair #define fi first #define se second #define pb push_back ll ppow(ll x, ll n) { ll ans = 1; while (n > 0) { if ((n & 1) == 1)ans = ans * x; x = x * x; n >>= 1; x %= mod; ans %= mod; } return ans; } string YN(bool b) { return(b ? "YES" : "NO"); } string yn(bool b) { return(b ? "Yes" : "No"); } ll sz, fact[N], inv[N]; void setinv() { fact[0] = 1; inv[0] = 1; for (int i = 1; i <= sz; i++) { fact[i] = (fact[i - 1] * i) % mod; //階乗を求める inv[i] = ppow(fact[i], (ll)mod - 2) % mod; // フェルマーの小定理で逆元を求める } } ll conv(ll r) {//nCr return fact[sz] * inv[r] % mod * inv[sz - r] % mod; } const ll MAXV = 55; ll V, E,d[MAXV][MAXV]; void reset() { rep(i, MAXV)rep(j, MAXV)d[i][j] = (i == j ? 0 : INF); } void warshall_floyd() { rep(k, V)rep(i, V)rep(j, V)d[i][j] = min(d[i][j], d[i][k] + d[k][j]); } ll s[55],ans=INF; int main() { cin >> V; rep(i, V)cin >> s[i]; cin >> E; reset(); rep(i, E) { int s, g, c; cin >> s >> g >> c; d[s][g] = c; d[g][s] = c; } warshall_floyd(); for (int i = 1; i < V-1; ++i) { for (int j = 1; j < V-1; ++j) { if (i == j)continue; ans = min(ans,(ll)d[0][i] + s[i] + s[j] + d[i][j] + d[j][V-1]); } } cout << ans << endl; }