P4568 分层图板子题(卡SPFA)
include<bits/stdc++.h>
define ll long long
using namespace std;
const int N=1e5+10;
int n,m,k,s,t;
ll vis[N<<4],dis[N<<4];
ll ans=INT_MAX;
vector<pair<int,int> > g[N<<4];
void dijkstra(int s)
{
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > q;
q.push({0,s});
dis[s]=0;
while(!q.empty())
{
int u=q.top().second;q.pop();
if(vis[u]) continue ;
vis[u]=1;
for(auto v:g[u])
{
if(dis[v.first]>dis[u]+v.second)
{
dis[v.first]=dis[u]+v.second;
q.push({dis[v.first],v.first});
}
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
memset(dis,0x7f,sizeof(dis));
// freopen("xxx.in","r",stdin);
// freopen("xxx.out","w",stdout);
cin>>n>>m>>k>>s>>t;
for(int i=1;i<=m;i++)
{
int a,b,c;
cin>>a>>b>>c;
for(int d=0;d<=k;d++)
{
g[Nd+a].push_back({Nd+b,c});
g[Nd+b].push_back({Nd+a,c});
if(d<k) g[Nd+a].push_back({N(d+1)+b,0});
if(d<k) g[Nd+b].push_back({N(d+1)+a,0});
}
}
dijkstra(s);
for(int d=0;d<=k;d++)
{
// cout<<dis[Nd+t]<<endl;
ans=min(ans,dis[Nd+t]);
}
cout<<ans<<endl;
return 0;
}