P2868 [USACO07DEC]Sightseeing Cows G(分数规划)

include

include

include

include

include

using namespace std;
int n,p;
double a[1000001];
int x,y,z;
struct e{
int to;
int v;
int ne;
}ed[1000001];
int pp;
int head[100001];
void add(int f,int to,int ne){
ed[++pp].to=to;
ed[pp].ne=head[f];
ed[pp].v=ne;
head[f]=pp;
}
int vis[1000001];
double dis[1000001];
int num[1000001];
bool check(double ke){
queue q;
for(int i=1;i<=n;++i){
q.push(i);
dis[i]=0;
vis[i]=1;
num[i]=1;
}
while(!q.empty()){
int x=q.front();
q.pop();
vis[x]=0;
for(int i=head[x];i;i=ed[i].ne){
int v=ed[i].to;
if(dis[v]>(double)dis[x]+keed[i].v-a[x]){
dis[v]=(double)dis[x]+ke
ed[i].v-a[x];
if(!vis[v]){
q.push(v);
vis[v]=1;
if(++num[v]>=n+10){
return 1;
}
}

		}
	}
}
return 0;

}
int main(){
scanf("%d%d",&n,&p);
for(int i=1;i<=n;++i){
cin>>a[i];
}
for(int i=1;i<=p;++i){
scanf("%d%d%d",&x,&y,&z);
add(x,y,z);
}
double l=0,r=1000010;
while(r-l>1e-4){
double mid=(l+r)/2;
if(check(mid)){
l=mid;
}else
r=mid;
}
printf("%.2lf",l);
return 0;
}

posted @ 2021-08-11 23:07  Simex  阅读(33)  评论(0编辑  收藏  举报