19pts 求调
查看原帖
19pts 求调
1140784
StarryRTX楼主2024/7/31 10:00

rt

#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<stack>
#define in inline
#define re register
#define MAXN 4000005
#define int long long
#define sped_cout_cin ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
int n,m,k,s,t,head[MAXN],dis[MAXN],a,b,c,cnt;
struct edge{int to,next,w;} e[MAXN];
bool vis[MAXN];
in void add(int u,int v,int w){
	e[++cnt].to=v;
	e[cnt].w=w;
	e[cnt].next=head[u];
	head[u]=cnt;
	return ;
}
in void dij(){
	typedef pair<int,int> p;
	priority_queue<p,vector<p>,greater<p> > q;
	dis[s]=0; vis[s]=1;
	q.push(make_pair(dis[s],s));
	while(!q.empty()){
		re int top=q.top().second;
		q.pop();
		vis[top]=0;
		for(re int i=head[top];i;i=e[i].next){
			re int to=e[i].to;
			if(dis[to]>dis[top]+e[i].w){
				dis[to]=dis[top]+e[i].w;
				if(!vis[to]){
					q.push(make_pair(dis[to],to));
					vis[to]=1;
				}
			}
		}
	}
	return ;
}
signed main(){
	sped_cout_cin
	memset(dis,0x3f,sizeof(dis));
	memset(head,-1,sizeof(head));
	cin>>n>>m>>k;
	cin>>s>>t;
	s++,t++;
	for(re int i=1;i<=m;i++){
		cin>>a>>b>>c;
		a++,b++;
		add(a,b,c);
		add(b,a,c);
		for(re int j=0;j<=k;j++){
			add(a+(j-1)*n,b+j*n,0);
			add(b+(j-1)*n,a+j*n,0);
			add(a+j*n,b+j*n,c);
			add(b+j*n,a+j*n,c);
		}
	}
	for(re int i=1;i<=k;i++) add(t+(i-1)*n,t+i*n,0);
	dij();
	cout<<dis[t+k*n]<<'\n';
	return 0;
}
2024/7/31 10:00
加载中...