#include #include #include #include using namespace std; #define int long long using P = pair; struct edge{ int to,cost; }; vector> dijkstra(vector>& Graph,int vertex, int start, int tickets){ #define INF 1e18 using PP = pair; #define weight first #define now second.first #define ticket second.second vector> dist(vertex,vector(tickets+1,INF)); priority_queue,vector,greater> Q; Q.push({0,{start,tickets}}); for(int i=0;i<=tickets;i++) dist[start][i] = 0; while(!Q.empty()){ PP p = Q.top(); Q.pop(); if(dist[p.now][p.ticket] < p.weight) continue; for(edge Edge : Graph[p.now]){ if(dist[Edge.to][p.ticket] < p.weight + Edge.cost) continue; dist[Edge.to][p.ticket] = p.weight + Edge.cost; Q.push({dist[Edge.to][p.ticket], {Edge.to,p.ticket}}); if(p.ticket > 0){ if(dist[Edge.to][p.ticket-1] < p.weight) continue; dist[Edge.to][p.ticket-1] = p.weight; Q.push({dist[Edge.to][p.ticket-1], {Edge.to,p.ticket-1}}); } } } return dist; } signed main(){ int N,M; cin >> N >> M; vector> Graph(N); for(int i=0;i> from >> to >> weight; from--, to--; Graph[from].push_back({to,weight}); Graph[to].push_back({from,weight}); } auto dist = dijkstra(Graph,N,0,1); for(int i=0;i