莫名其妙的被强制转换成了int型,求助QWQ
查看原帖
莫名其妙的被强制转换成了int型,求助QWQ
497332
利姆露·三上悟楼主2022/3/3 19:26
#include<bits/stdc++.h>
using namespace std;
const int n1=100010;const int m1=500010;
struct EDGE
{
	int u,v,next;
	double w;
}a[m1];
int head[n1],tot;double dis[n1];
bool vis[n1];
int n,m,s,end;
void add(int x,int y,double z)
{
	a[++tot].v=y,a[tot].w=z/100;
	a[tot].next=head[x],head[x]=tot;
}
struct node
{
    double dis;
    int pos;
    bool operator <( const node &x )const
    {
        return x.dis < dis;
    }
};
priority_queue<node> q;
void dijkstra()
{
	dis[s]=100;
	q.push((node){0,s});
	while(!q.empty())
	{
		node tp=q.top();
		q.pop();
		int  x=tp.pos;double d=tp.dis;
		if(vis[x])continue;
		vis[x]=1;
		for(int i=head[x];i;i=a[i].next)
		{
			int y=a[i].v;
			if(dis[y]>dis[x]+dis[x]*a[i].w)
			{
				dis[y]=dis[x]+dis[x]*a[i].w;
				{
					if(!vis[y])
					{
						q.push((node){dis[y],y});
					}
				}
			}
		}
	}
}
int main()
{
	cin>>n>>m;
	for(int i = 1; i <= n; ++i)dis[i] = 0x7fffffff;
	for(int i=0;i<m;i++)
	{
		int x,y;double z;
		cin>>x>>y>>z;
		add(x,y,z);
	}
	cin>>s>>end;
	dijkstra();
	printf("%.8lf",dis[end]);
}
2022/3/3 19:26
加载中...