比赛 |
2024暑假C班集训A |
评测结果 |
AAAWWWAAAA |
题目名称 |
行动!行动! |
最终得分 |
70 |
用户昵称 |
┭┮﹏┭┮ |
运行时间 |
0.329 s |
代码语言 |
C++ |
内存使用 |
12.93 MiB |
提交时间 |
2024-07-10 08:48:01 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll,int>
const int N = 3e6+10;
const ll inf = 1e17;
ll read(){
ll x = 0,f = 1;char c = getchar();
for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
return x * f;
}
int n,m,k,s,t;
struct made{
int ver,nx;ll ed;
}e[N<<1];
int hd[N],tot;
void add(int x,int y,ll z){e[++tot] = {y,hd[x],z},hd[x] = tot;}
ll d[N];
bool v[N];
void dij(int u){
memset(v,0,sizeof v);
for(int i = 1;i <= n * (k+1);i++)d[i] = inf;
priority_queue<pii,vector<pii>,greater<pii> >q;
q.push(make_pair(0,u)),d[u] = 0;
while(!q.empty()){
int x = q.top().second;q.pop();
if(v[x])continue;
v[x] = 1;
for(int i = hd[x];i;i = e[i].nx){
int y = e[i].ver;ll z = e[i].ed;
if(d[y] > d[x] + z){
d[y] = d[x] + z;
q.push(make_pair(d[y],y));
}
}
}
}
int main(){
freopen("move.in","r",stdin);
freopen("move.out","w",stdout);
//编号0~n-1
n = read(),m = read(),k = read(),s = read() + 1,t = read() + 1;
for(int i = 1;i <= m;i++){
int x = read() + 1,y = read() + 1;ll z = read();
add(x,y,z),add(y,x,z);
for(int j = 1;j <= k;j++){
add(x + n * (j-1),y + n * j,0);
add(x + n * j,y + n * j,z);
add(y + n * j,x + n * j,z);
}
}
dij(s);
ll ans = inf;
for(int i = 0;i <= k;i++)ans = min(ans,d[t + n * i]);
printf("%lld\n",ans);
return 0;
}