已AC,求解释
  • 板块P1576 最小花费
  • 楼主chidor
  • 当前回复6
  • 已保存回复6
  • 发布时间2025/1/4 22:44
  • 上次更新2025/1/5 12:24:37
查看原帖
已AC,求解释
750297
chidor楼主2025/1/4 22:44

rt,这份代码用的是dijkstra,但最慢点有913ms,感觉不太对

#include<bits/stdc++.h>
#define maxn 2005
typedef double db;
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int n;
int m;
struct node{
	int u;
	db w;
	bool operator < (node t)const{
		return w>t.w;
	}
};
struct edge{
	int v;
	db w;
};
int s,t;
db dis[maxn];
bool vis[maxn];
vector<edge>e[maxn];
priority_queue<node>q;
void dijkstra_2(){
	vis[s]=1;
	dis[s]=1;
	q.push({s,1});
	while(!q.empty()){
		int u=q.top().u;
		q.pop();
		vis[u]=1;
		for(auto v:e[u]){
			if(dis[u]*v.w>dis[v.v]){
				dis[v.v]=dis[u]*v.w;
				q.push({v.v,dis[v.v]});
			}
		}
	}
	return;
}
int main(){
	cin>>n>>m;
	for(int i=1,u,v,w;i<=m;i++){
		cin>>u>>v>>w;
		db t=(100-w)/100.0;
		e[v].push_back({u,t});
		e[u].push_back({v,t});
	}
	cin>>s>>t; 
	dijkstra_2();
	printf("%.8lf\n",(100/dis[t])); 
	return 0;
}

2025/1/4 22:44
加载中...