求助!!!
  • 板块学术版
  • 楼主xiaoruifeng
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/3/28 11:12
  • 上次更新2024/3/28 16:32:36
查看原帖
求助!!!
1257375
xiaoruifeng楼主2024/3/28 11:12

求助 P4568 [JLOI2011] 飞行路线

#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);
   cout<<dis[yy+e*q];
   return 0;
}

WA了最后一个点 不是TLE

2024/3/28 11:12
加载中...