题面
Solution
据说本题可以分层图+SPFA过?反正我没有尝试,直接Dp不就好了吗?QAQ
// luogu-judger-enable-o2
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<queue>
#define ll long long
#define file(a) freopen(a".in","r",stdin)//;freopen(a".out","w",stdout)
using namespace std;
inline int gi(){
int sum=0,f=1;char ch=getchar();
while(ch>'9' || ch<'0'){if(ch=='-')f=-f;ch=getchar();}
while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
return f*sum;
}
inline ll gl(){
ll sum=0,f=1;char ch=getchar();
while(ch>'9' || ch<'0'){if(ch=='-')f=-f;ch=getchar();}
while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
return f*sum;
}
const int N=10010,M=50010;
int to[M<<1],nxt[M<<1],w[M<<1],front[N],cnt;
int dp[N][20],s,t,vis[N];
queue<int >Q;
void Add(int u,int v,int W){
to[++cnt]=v;nxt[cnt]=front[u];front[u]=cnt;
w[cnt]=W;
}
int main(){
int i,j,n,m,k;
n=gi();m=gi();k=gi();
s=gi();t=gi();s++;t++;
for(i=1;i<=m;i++){
int u=gi(),v=gi(),c=gi();
u++;v++;
Add(u,v,c);Add(v,u,c);
}
memset(dp,127,sizeof(dp));
Q.push(s);dp[s][0]=0;vis[s]=1;
while(!Q.empty()){
int u=Q.front();Q.pop();vis[u]=0;
for(i=front[u];i;i=nxt[i]){
int v=to[i];
for(j=0;j<=k;j++){
if(j>0 && dp[v][j]>dp[u][j-1]){
dp[v][j]=dp[u][j-1];
if(!vis[v]){Q.push(v);vis[v]=1;}
}
if(dp[v][j]>dp[u][j]+w[i]){
dp[v][j]=dp[u][j]+w[i];
if(!vis[v]){Q.push(v);vis[v]=1;}
}
}
}
}
int ans=2e9;
for(i=0;i<=k;i++)
ans=min(ans,dp[t][i]);
printf("%d
",ans);
return 0;
}