最小花费(单源最短路)


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

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

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

样例
input

3 3
1 2 1
2 3 2
1 3 3
1 3

output

103.07153164
#include<bits/stdc++.h>
using namespace std; using ll = long long;
int dir[4][2] = { 1, 0, -1, 0, 0, 1, 0, -1 };
//using lll = __int128; template <class T> istream& read(T& x, istream& cin = std::cin) { T num = 0; bool f = 0; char ch = 0; while (!isdigit(ch)) { f |= ch == '-'; if (!cin.get(ch)) return cin; }while (isdigit(ch)) { num = (num << 3) + (num << 1) + (ch ^ 48); if (!cin.get(ch)) break; }x = f ? -num : num; return cin; }template <class T> ostream& write(T x, ostream& cout = std::cout) { if (x < 0) cout.put('-'), x = -x; if (x > 9) write(x / 10); cout.put(x % 10 + '0'); return cout; }ostream& operator<<(ostream& cout, lll x) { write(x); return cout; }istream& operator>>(istream& cin, lll& x) { return read(x); }bool check(int i, int j);
bool check(int i, int j);

const int N = 1e5 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f;

using pid = pair<int, double>;

vector<pid> g[N];

int n, m, S, E;

double dist[N];

bool st[N];

void init() {
	cin >> n >> m;
	for (int i = 0; i <= n; i++)
		dist[i] = INF;
	while (m--) {
		int a, b, c;
		cin >> a >> b >> c;
		g[a].emplace_back(b, 1 - c / 100.0);
		g[b].emplace_back(a, 1 - c / 100.0);
	}
	cin >> S >> E;
	return;
}

using pdi = pair<double, int>;

double dijkstra() {
	priority_queue<pdi, vector<pdi>, greater<pdi>> qu;
	qu.emplace(100, S);
	dist[S] = 100;
	while (qu.size()) {
		auto [d, x] = qu.top();
		cout << d << endl;
		qu.pop();
		if (st[x]) continue;
		st[x] = true;
		for (auto& [nx, td] : g[x]) {
			if (dist[nx] > d / td) {
				dist[nx] = d / td;
				qu.emplace(dist[nx], nx);
			}
		}
	}
	cout << endl;
	return dist[E];
}

void solve() {
	cout << dijkstra();
	return;
}

int main(void) {
	ios::sync_with_stdio(0); cin.tie(0); cout << setprecision(8) << fixed;
	int TT = 1;
	//cin >> TT;
	for (int ii = 1; ii <= TT; init(), solve(), ii++, cout << "\n") {}
	return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值