acwing .361.观光的奶牛
作者:互联网
#include<bits/stdc++.h> #define N 10010 using namespace std; int head[N],to[N],vis[N],net[N],cut; int num[N],f[N]; int vv[N]; queue<int>dl; double dis[N]; int l,p; void add(int from,int t,int v) { net[++cut]=head[from]; to[cut]=t; vis[cut]=v; head[from]=cut; } int spfa(double mid)//数据类型要一致 { for(int i=1;i<=l;i++) dl.push(i),f[i]=1,dis[i]=num[i]=0; while(dl.size()) { int x=dl.front(); dl.pop(); f[x]=0; for(int i=head[x];i;i=net[i]) { int y=to[i]; double v=vis[i]*mid-vv[x]; if(dis[x]+v<dis[y]) { dis[y]=dis[x]+v; num[y]=num[x]+1; if(num[y]>=p)return 1; if(!f[y]) { dl.push(y); f[y]=1; } } } } return 0; } int main() { scanf("%d%d",&l,&p); for(int i=1;i<=l;i++) scanf("%d",&vv[i]); for(int i=1;i<=p;i++) { int x,y,z; scanf("%d%d%d",&x,&y,&z); add(x,y,z); } double l=0,r=1e8; while(r-l>0.0001) { double mid=(l+r)/2; if(spfa(mid))l=mid; else r=mid; } printf("%.2lf",r); return 0; }
标签:head,cut,return,int,double,mid,361,奶牛,acwing 来源: https://www.cnblogs.com/1314cyd/p/15001671.html