#include #include #include #define mp std::make_pair typedef std::pair P; typedef std::pair State; int N, M, S[50]; std::vector

G[50]; int main(){ scanf("%d", &N); for(int i=0;i, std::greater > q; q.push(mp(0, mp(0, 50))); while(!q.empty()){ State s = q.top(); q.pop(); int cost = s.first, from = s.second.first, state = s.second.second; if(state == 50 && from != 0 && from != N-1 && d[from][from] > cost + S[from]){ d[from][from] = cost + S[from]; q.push(mp(d[from][from], mp(from, from))); } if(0 <= state && state < N && from != 0 && from != N-1 && from != state && d[from][51] > cost + S[from]){ d[from][51] = cost + S[from]; q.push(mp(d[from][51], mp(from, 51))); } for(auto e : G[from]){ if(d[e.first][state] > cost + e.second){ d[e.first][state] = cost + e.second; q.push(mp(d[e.first][state], mp(e.first, state))); } } } printf("%d\n", d[N-1][51]); }