#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include typedef long long ll; using namespace std; #ifndef LOCAL #define debug(x) ; #else #define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl; template ostream &operator<<(ostream &out, const pair &p) { out << "{" << p.first << ", " << p.second << "}"; return out; } template ostream &operator<<(ostream &out, const vector &v) { out << '{'; for (const T &item : v) out << item << ", "; out << "\b\b}"; return out; } #endif #define mod 1000000007 //1e9+7(prime number) #define INF 1000000000 //1e9 #define LLINF 2000000000000000000LL //2e18 #define SIZE 200010 /* Dijkstra O(NlogM)*/ template struct Dijkstra{ int V; vector>> G; vector cost; Dijkstra(int n): V(n), G(n, vector>()) {} void add_edge(int u, int v, Type c){ G[u].push_back({v, c}); } Type solve(int s, int g = -1){ cost.assign(V, -1); priority_queue> pq; Type max_cost = 0; pq.push({0, s}); while(pq.size()){ Type now_cost = pq.top().first; int now = pq.top().second; pq.pop(); if(cost[now] >= 0) continue; cost[now] = -now_cost; max_cost = max(max_cost, -now_cost); if(now == g) return -now_cost; for(int i=0; i<(int)G[now].size(); i++) pq.push({now_cost - G[now][i].second, G[now][i].first}); } return max_cost; } }; int main(){ int n, m; scanf("%d%d", &n, &m); Dijkstra dijk(n*2); for(int i=0;i