思路:
先反向建图 Dijkstra一遍 求出h数组
再正向建图 A_star一遍 搞定
//By SiriusRen
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define int long long
#define N 10050
int first[N],next[N],v[N],w[N],tot,h[N],vis[N],ans[N];
int n,m,k,xx[N],yy[N],zz[N];
struct Node{int h,g,now;}jy;
priority_queue<Node>pq;
void add(int x,int y,int z){w[tot]=z,v[tot]=y,next[tot]=first[x],first[x]=tot++;}
bool operator < (Node a,Node b){
return a.h+a.g>b.h+b.g;
}
void Dijkstra(){
jy.now=1,pq.push(jy);
for(int i=2;i<=n;i++)h[i]=0x3ffffff;
while(!pq.empty()){
int x=pq.top().now;pq.pop();
if(vis[x])continue;
vis[x]=1;
for(int i=first[x];~i;i=next[i])
if(h[v[i]]>h[x]+w[i]){
h[v[i]]=h[x]+w[i];
jy.h=h[v[i]],jy.now=v[i];
pq.push(jy);
}
}
}
void A_star(){
jy.h=jy.g=0,jy.now=n;pq.push(jy);
while(!pq.empty()){
Node t=pq.top();pq.pop();
if(vis[t.now]>k)continue;
if(t.now==1)ans[vis[1]]=t.g;
vis[t.now]++;
for(int i=first[t.now];~i;i=next[i]){
jy.h=h[v[i]],jy.g=t.g+w[i],jy.now=v[i];
pq.push(jy);
}
}
}
signed main(){
memset(first,-1,sizeof(first));
scanf("%lld%lld%lld",&n,&m,&k);
for(int i=1;i<=m;i++){
scanf("%lld%lld%lld",&xx[i],&yy[i],&zz[i]);
add(yy[i],xx[i],zz[i]);
}
Dijkstra();
memset(first,-1,sizeof(first)),tot=0;
for(int i=1;i<=m;i++)add(xx[i],yy[i],zz[i]);
A_star();
for(int i=1;i<vis[1];i++)printf("%lld
",ans[i]);
for(int i=vis[1];i<=k;i++)puts("-1");
}