多开一维表示层数(免费坐了几次)
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<cctype>
#include<cmath>
#include<ctime>
#include<queue>
using namespace std;
#define getchar() (frS==frT&&(frT=(frS=frBB)+fread(frBB,1,1<<12,stdin),frS==frT)?EOF:*frS++)
char frBB[1<<12],*frS=frBB,*frT=frBB;
inline void read(int&T)
{
int x=0;char ch=getchar();bool w=0;
while(!isdigit(ch))w|=(ch=='-'),ch=getchar();
while(isdigit(ch))x=x*10+(ch-48),ch=getchar();
T=w?-x:x;
}
#define ll long long
#define PII pair<ll,pair<int,int> >
#define add_edge(a,b,c) nxt[++tot]=head[a],head[a]=tot,val[tot]=c,to[tot]=b
priority_queue<PII,vector<PII>,greater<PII> >Q;
int N,M,K,tot=0,S,T;
ll ans=2147483647147483647ll;
int head[10005]={},nxt[100005]={},to[100005]={};
ll val[100005]={};
ll dis[10005][12]={};
bool vis[10005][12]={};
void dijkstra()
{
memset(vis,0,sizeof(vis));
for(int i=0;i<N;++i)for(int j=0;j<=K;++j)dis[i][j]=2147483647147483647ll;
dis[S][0]=0; Q.push(make_pair(0,make_pair(S,0)));
pair<int,int> p;
int x,c;
while(!Q.empty())
{
p=Q.top().second;
x=p.first; c=p.second;
Q.pop(); vis[x][c]=1;
for(int i=head[x];i;i=nxt[i])
{
if((c<K)&&(dis[to[i]][c+1]>dis[x][c]))
{
dis[to[i]][c+1]=dis[x][c];
if(!vis[to[i]][c+1])Q.push(make_pair(dis[to[i]][c+1],make_pair(to[i],c+1)));
}
if(dis[to[i]][c]>dis[x][c]+val[i])
{
dis[to[i]][c]=dis[x][c]+val[i];
if(!vis[to[i]][c])Q.push(make_pair(dis[to[i]][c],make_pair(to[i],c)));
}
}
}
}
int main()
{
scanf("%d%d%d%d%d",&N,&M,&K,&S,&T);
for(int a,b,i=1;i<=M;++i)
{
ll c;
scanf("%d%d%lld",&a,&b,&c);
add_edge(a,b,c);
add_edge(b,a,c);
}
dijkstra();
for(int i=0;i<=K;++i)ans=min(ans,dis[T][i]);
printf("%lld",ans);
return 0;
}