题目链接:
https://www.luogu.org/problem/P1576
参考博客:
这个博客思路真心清晰:https://www.luogu.org/blog/user17511/solution-p1576
思路:
1:方向:最长路的变形问题
2:首先我们可以发现两个人之间实际的汇率是 1-z% 那么我们就可以将人抽象成点,把两个人之间的汇率记做边权
3:如果A到B的汇率是 x ,B到C的汇率是y那么A到C的汇率就是x*y,所以原来spfa模板中更新权值就可以改成乘的形式
4:因为最后要求出最少的汇款,所以就要求A与B之间的汇率最大,那么现在就很显然了,就是求最长路
#include <bits/stdc++.h>
using namespace std;
const int maxn=2e3+1;
vector<pair<int,double> >e[maxn];
int n,m,ing[maxn],a,b,c,s,t;
double d[maxn];
inline void spfa(int s)
{
memset(ing,0,sizeof(ing));
memset(d,0,sizeof(d));
queue<int>q;
q.push(s);
d[s]=1;
ing[s]=1;
while(!q.e