最小花费——最短路

在 n 个人中,某些人的银行账号之间可以互相转账。这些人之间转账的手续费各不相同。给定这些人之间转账时需要从转账金额里扣除百分之几的手续费,请问 A 最少需要多少钱使得转账后 B 收到 100 元。

输入格式
第一行输入两个正整数 n,m,分别表示总人数和可以互相转账的人的对数。
以下 m 行每行输入三个正整数 x,y,z,表示标号为 x 的人和标号为 y 的人之间互相转账需要扣除 z% 的手续费 ( z<100 )。
最后一行输入两个正整数 A,B。
数据保证 A 与 B 之间可以直接或间接地转账。

输出格式
输出 A 使得 B 到账 100 元最少需要的总费用。精确到小数点后 8 位。

数据范围
1≤n≤2000,m≤105

输入样例:
3 3
1 2 1
2 3 2
1 3 3
1 3

输出样例:
103.07153164

#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef pair<double,int> PII;
const int N=100000;
struct node
{
    int v,w;
};
vector <node> g[N];
int n,m,l,r;
double d[N];
bool vis[N];
void dijkstra()
{
    double y=100.0;
    priority_queue <PII,vector<PII>,greater<PII>> q;
    for (int i=1;i<=n;i++) d[i]=1000000.0;
    d[r]=100.0;
    q.push({y,r});
    while (q.size())
    {
        double tance=q.top().first;
        int u=q.top().second;
        q.pop();
        if (vis[u]) continue;
        vis[u]=1;
        for (auto x:g[u])
        {
            int v=x.v,w=x.w;
            if (d[v]>tance*100.0/(100-w))
            {
                d[v]=tance*100.0/(100-w);
                q.push({d[v],v});
            }
        }
    }
}
signed main()
{
    cin>>n>>m;
    while (m--)
    {
        int a,b,w;
        cin>>a>>b>>w;
        
        g[a].push_back({b,w});
        g[b].push_back({a,w});
    }
    cin>>l>>r;
    dijkstra();
    printf("%.8lf",d[l]);
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值