#include #define mp make_pair #define mt make_tuple #define pb push_back #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair pii; typedef pair pll; const int INF = 1 << 29; const double EPS = 1e-9; const int MOD = 100000007; const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1}; int N,M; vector S; int dist[55][55]; int main() { cin >> N; S.resize(N); for (int i = 0; i < N; i++){ cin >> S[i]; } cin >> M; for (int i = 0; i < 55; i++){ for(int j = 0; j < 55; j++){ dist[i][j] = INF; if (i == j)dist[i][j] = 0; } } for (int i = 0; i < M; i++){ int A,B,C; cin >> A >> B >> C; dist[A][B] = C; dist[B][A] = C; } for (int k = 0; k < N; k++){ for (int i = 0; i < N; i++){ for (int j = 0; j < N; j++){ dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); } } } ll result = 1LL << 50; for (int i = 1; i < N - 1; i++){ for (int j = 1; j < N - 1; j++){ if (i == j)continue; ll res = dist[0][i] + S[i] + dist[i][j] + S[j] + dist[j][N - 1]; result = min(result, res); } } cout << result << endl; return 0; }