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