分层图最短路大水题
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
const int N=10005,M=50005,K=25;
struct Node{
int x,k,dis;
bool operator < (const Node &rhs) const {return dis>rhs.dis;}
};
struct Edge{
int to,nxt,val;
}e[M<<1];
priority_queue<Node> q;
int dis[N][K],n,m,k,head[N],ecnt;
bool vis[N][K];
inline void add(int bg,int ed,int val) {e[++ecnt]=(Edge){ed,head[bg],val};head[bg]=ecnt;}
inline void ins(int bg,int ed,int val) {add(bg,ed,val);add(ed,bg,val);}
void dij() {
memset(dis,0x3f,sizeof dis);
vis[1][0]=1;
dis[1][0]=0;
q.push((Node){1,0,0});
while(!q.empty()) {
Node u=q.top();q.pop();
if(u.dis!=dis[u.x][u.k]) continue;
for(int i=head[u.x];i;i=e[i].nxt) {
int v=e[i].to;
if(u.k<k) if(dis[u.x][u.k]<dis[v][u.k+1]) dis[v][u.k+1]=dis[u.x][u.k],q.push((Node){v,u.k+1,u.dis});
if(dis[v][u.k]>dis[u.x][u.k]+e[i].val) dis[v][u.k]=dis[u.x][u.k]+e[i].val,q.push((Node){v,u.k,dis[v][u.k]});
}
}
}
int main() {
scanf("%d%d%d",&n,&m,&k);
for(int i=1,a,b,c;i<=m;i++) scanf("%d%d%d",&a,&b,&c),ins(a,b,c);
dij();
printf("%d
",dis[n][k]);
}