求助!!!

学术版

@[xiaoruifeng](/user/1257375) [看讨论区的这篇帖子,下面是给你改的Ac代码](https://www.luogu.com.cn/discuss/798248) ```cpp #include<bits/stdc++.h> #define int long long const int MAXN(1e4 + 5), MAXM(5e4 + 5), MAXK(15); using namespace std; struct tu{ int nex,to,len; }edge[MAXM*MAXK*4]; struct oiwet{ int name,v; }; int head[MAXN*MAXK]; int dis[MAXN*MAXK]; int vis[MAXN*MAXK]; int q,w,e,r,t; int n,m; priority_queue<oiwet>asd; inline void add(int h,int tt,int di) { edge[++n].nex=head[h]; edge[n].to=tt; edge[n].len=di; head[h]=n; } bool operator <(oiwet a,oiwet b) { return a.v>b.v; } inline void dijstra(int po) { memset(dis,0x3f,sizeof(dis)); dis[po]=0; oiwet l; l.name=po; l.v=0; asd.push(l); while(!asd.empty()) { oiwet zxc; zxc=asd.top(); asd.pop(); if(vis[zxc.name]) continue; vis[zxc.name]=1; for(int x=head[zxc.name];x;x=edge[x].nex) { if(dis[edge[x].to]>dis[zxc.name]+edge[x].len) { dis[edge[x].to]=dis[zxc.name]+edge[x].len; oiwet tmp; tmp.name=edge[x].to; tmp.v=dis[edge[x].to]; asd.push(tmp); } } } } signed main() { cin>>q>>w>>e; int xx,yy; cin>>xx>>yy; for(int i=1;i<=w;i++) { int x,y,z; cin>>x>>y>>z; add(x,y,z); add(y,x,z); for(int j=1;j<=e;j++) { add(x+(j-1)*q,y+j*q,0); add(y+(j-1)*q,x+j*q,0); add(x+j*q,y+j*q,z); add(y+j*q,x+j*q,z); } } dijstra(xx); int ans=dis[yy]; for(int i=1;i<=e;i++){ ans=min(ans,dis[yy+i*q]); } cout<<ans; return 0; } ```
by ka_da_Duck @ 2024-03-28 16:27:00


@[ka_da_Duck](/user/1088058) 谢大佬
by xiaoruifeng @ 2024-03-28 19:40:49


|