// #define _GLIBCXX_DEBUG // for STL debug (optional) #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define debug(...) fprintf(stderr, __VA_ARGS__) #define int long long int template void chmax(T &a, T b) {a = max(a, b);} template void chmin(T &a, T b) {a = min(a, b);} template void chadd(T &a, T b) {a = a + b;} typedef pair pii; typedef long long ll; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; const ll INF = 1001001001001001LL; const ll MOD = 1000000007LL; using Graph = vector< vector< pair > >; int N, M; int dist[100010][2]; struct Elem { int pos, mode, cost; Elem() {} Elem(int p, int m, int c) : pos(p), mode(m), cost(c) {} bool operator<(const Elem &e) const { return cost > e.cost; } }; signed main() { scanf("%lld%lld", &N, &M); Graph G(N); for(int i=0; i que; que.emplace(0, 0, 0); while(que.size()) { auto cur = que.top(); que.pop(); if(dist[cur.pos][cur.mode] < cur.cost) continue; for(auto e : G[cur.pos]) { int u = cur.pos, v = e.first, w = e.second; int new_cost = cur.cost + w; // そのまま進む if(dist[v][cur.mode] > new_cost) { dist[v][cur.mode] = new_cost; que.emplace(v, cur.mode, new_cost); } // 0 -> 1 if(cur.mode == 0) { if(dist[v][1] > cur.cost) { dist[v][1] = cur.cost; que.emplace(v, 1, cur.cost); } } } } for(int i=0; i