#include using namespace std; int S[50]; int dist[50][50][50]; vector > adj[50]; int n,m,a,b,c; int main(void) { cin.tie(0); ios::sync_with_stdio(false); cin >> n; for(int i=0;i> S[i]; } cin >> m; for(int i=0;i> a >> b >> c; adj[a].push_back({b,c}); adj[b].push_back({a,c}); } for(int i=0;i>>,vector>>>,greater>>>> pque; pque.push(make_pair(0,make_pair(0,make_pair(0,0)))); while(!pque.empty()) { int now = pque.top().second.first; int t1 = pque.top().second.second.first; int t2 = pque.top().second.second.second; if(dist[now][t1][t2] < pque.top().first) { pque.pop(); continue; } pque.pop(); //cout << now << ' ' << t1 << ' ' << t2 << '\n'; //cout << now << ' ' << cnt << ' ' << dist[now][cnt] << ' ' << S[now] << '\n'; for(auto it : adj[now]) { int next = it.first; int cost = it.second; if(dist[next][t1][t2] > dist[now][t1][t2] + cost) { dist[next][t1][t2] = dist[now][t1][t2] + cost; pque.push(make_pair(dist[next][t1][t2],make_pair(next,make_pair(t1,t2)))); } if(now!=0 && now!=n-1) { if(t1==0) { if(dist[next][now][t2] > dist[now][t1][t2] + cost + S[now]) { dist[next][now][t2] = dist[now][t1][t2] + cost + S[now]; pque.push(make_pair(dist[next][now][t2],make_pair(next,make_pair(now,t2)))); } } else if(t2==0) { if(t1!=now) { if(dist[next][t1][now] > dist[now][t1][t2] + cost + S[now]) { dist[next][t1][now] = dist[now][t1][t2] + cost + S[now]; pque.push(make_pair(dist[next][t1][now],make_pair(next,make_pair(t1,now)))); } } } } } } int res = 1e9; for(int i=1;i