蒟蒻全wa求助
查看原帖
蒟蒻全wa求助
902195
appIe365楼主2023/1/4 13:23

rt,样例过了

#include<bits/stdc++.h>
using namespace std;
const int N = 2005,M = 100005;
struct node{
	int to,next,w;
}eg[M];
int n,m,s,t;
int head[N],tot;
void add(int x,int y,int w){
	eg[++tot].to = y,eg[tot].w = w,eg[tot].next = head[x],head[x] = tot;
}
bool vis[N];
double dis[N];
void dijkstra(int s){
    priority_queue<pair<double,int>> hp;
    for(int i = 1;i <= n;i ++)
    	dis[i] = (1 << 30);
    dis[s] = 100;
    hp.push(make_pair(-100,s));
    while(hp.size()){
        auto cur = hp.top();
        hp.pop();
        int w = cur.first,u = cur.second;
        if(vis[u]) continue;
        vis[u] = 1;
        for(int i = head[u];i;i = eg[i].next){
            int y = eg[i].to;
            if(dis[y] > dis[u]/(1- (double)0.01*eg[i].w)){
                dis[y] = dis[u]/(1- (double)0.01*eg[i].w);
                hp.push(make_pair(-dis[y],y));
            }
        }
    }
}
int main(){
	cin >> n >> m;
	int a,b,c;
	for(int i = 1;i <= n;i ++){
		cin >> a >> b >> c;
		add(a,b,c);
		add(b,a,c);
	}
	cin >> t >> s;
	dijkstra(s);
	printf("%.8f",dis[t]);
	return 0;
}
2023/1/4 13:23
加载中...