在 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;
- }