0分蒟蒻求助
查看原帖
0分蒟蒻求助
348197
绊城烟雨“grz楼主2021/2/7 22:32

整整10个WA,样例过了

#include<bits/stdc++.h>
using namespace std;
const int MAXN=2e5+10;
int n,m,cnt,s,t;
double head[MAXN],vis[MAXN],dist[MAXN];
struct node{
	int nxt,to;
	double w;
}e[MAXN];
struct point{
	int id;
	double dis;
	friend bool operator < (point a,point b){
		return a.dis>b.dis;
	}
};
void add(int x,int y,double z){
	e[++cnt].nxt=head[x];
	e[cnt].to=y;
	e[cnt].w=1.0-z;
	head[x]=cnt;
}
priority_queue<point>q;
void dij(){
	memset(dist,-0x3f,sizeof(dist));
	dist[s]=1.0;
	q.push({s,1.0});
	while(!q.empty()){
		int tmp=q.top().id;
		q.pop();
		if(vis[tmp])
			continue;
		vis[tmp]=1;
		for(int i=head[tmp];i;i=e[i].nxt){
			int v=e[i].to;
			double w=e[i].w;		
			if(dist[v]<dist[tmp]*w){
				dist[v]=dist[tmp]*w;
				q.push({v,dist[v]});
			}
		}
	}
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int x,y;
		double z;
		cin>>x>>y>>z;
		add(x,y,z/100.0);
		add(y,x,z/100.0);
	}
	cin>>s>>t;
	dij();
	printf("%.8lf",100/dist[t]);
	return 0;
}

真的不知道哪里错了....真心求助

2021/2/7 22:32
加载中...