#include #include using namespace std; #define INF 10000000 int main(){ int n, m; cin >> n; int s[n]; for(int i = 0; i < n; i++) cin >> s[i]; int dist[n][n]; fill(dist[0], dist[n], INF); for(int i = 0; i < n; i++) dist[i][i] = 0; cin >> m; while(m--){ int a, b, c; cin >> a >> b >> c; dist[a][b] = dist[b][a] = min(dist[a][b], 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]); int ans = 1e9; for(int i = 1; i < n - 1; i++) for(int j = 1; j < n - 1; j++) if(i != j) ans = min(ans, dist[0][i] + dist[i][j] + dist[j][n - 1] + s[i] + s[j]); cout << ans << endl; }