luogu P3288

Topic Link

The meaning of problems

There is a DAG full flow, where the starting point is only one out of the side, and then each side has the expansion and compression costs, as well as units of traffic costs, in addition to the starting point of the connected side can not be modified capacity, the other side can be asked at least to modify an edge case and the maximum flow rate is not reduced, X Y K \frac{X-Y}{K} What is the maximum, where X represents the original cost of transportation, Y indicates that the current transport costs + cost of modifying edge capacity, K represents the number of modified edge capacities.
Data Assurance answer is greater than 0

data range

1 <= N <= 5000
0 <= C <= 3000
1 ≤ Ui, Vi <= N + 2,
0 <= Ai Bi <= 500
0 <= Ci <= 10 000
0 <= Di <= 1000

solution

Because in addition to K-style house with an operation, you can think scores planning:
the formula into
X Y = = K a n s XY == K * years
then consider the full flow picture itself, can be compressed as it flows back, as augmented expansion. If the flow is greater than the original and because the flow rate is not necessarily excellent, the final flow rate is fixed and each edge at most we will be modified once (this is important).

Then build chart, for a picture of the edge, if it has to build a counter-flow edge in the new graph, with a weight of a d a-d , then while each picture to be built in a new image in the same direction, the weight b + d b+d edges. (These weights are because we can modify each edge at most once, these weights is a change in the price). We then half the answer a n s years , in the new image to the weights of each edge plus ANS, to see if a negative ring, if there is, it shows X Y > K a n s XY> K * years , the condition is not satisfied.

This is because each make an adjustment, the equivalent of taking a side on the new map, the right side of the set value w w so X Y = = X ( X + w ) = = w X-Y==X-(X+\sum w)==-\sum w , so if a new plus ANS FIG Every edge, the ring will be negative, indicating
w > k a n s -\sum w\gt k*ans , s finally starting to remember that one side can not be modified, while typing sentenced click on it.

#include<bits/stdc++.h>
using namespace std;
const int maxn=3e4+5;
const double eps=1e-4,inf=1e9;
inline int read(){
	char c=getchar();int t=0,f=1;
	while((!isdigit(c))&&(c!=EOF)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)&&(c!=EOF)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
int n,m,s,t;
struct edge{
	int v,p,w;
}e[maxn<<1];
int h[maxn],tot;
inline void add(int a,int b,int c){
	e[++tot].p=h[a];
	e[tot].v=b;
	e[tot].w=c;
	h[a]=tot;
}
int inq[maxn],cnt[maxn];
double dis[maxn];
bool spfa(double x){
	memset(inq,0,sizeof(inq));
	memset(cnt,0,sizeof(cnt));
	for(int i=1;i<=n;i++)dis[i]=inf;
	queue<int> q;while(!q.empty())q.pop();
	q.push(s);dis[s]=0;cnt[s]++;
	while(!q.empty()){
		int u=q.front();q.pop();inq[u]=0;
		for(int i=h[u];i;i=e[i].p){
			int v=e[i].v;
			double len=e[i].w+x;
			if(dis[v]>dis[u]+len){
				dis[v]=dis[u]+len;
				if(inq[v])continue;
				inq[v]=1;cnt[v]++;if(cnt[v]>n)return 1;
				q.push(v);
			}
		}
	}
	return 0;
}
int main(){
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	n=read(),m=read();
	s=n+1,t=n+2;n+=2;
	double l=0,r=0;
	for(int i=1;i<=m;i++){
		int u=read(),v=read(),a=read(),b=read(),c=read(),d=read();
		if(u==n+1){s=v;continue;}
		if(c)add(v,u,a-d);
		add(u,v,b+d);
		if(a-d<0)r+=d-a;
	}
	double ans=0;
	while(r-l>=eps){
		double mid=(l+r)/2;
		if(spfa(mid)){
			ans=mid;l=mid;
		}
		else r=mid;
	}
	printf("%.2lf\n",ans);
	return 0;
}

Published 61 original articles · won praise 1 · views 975

Guess you like

Origin blog.csdn.net/wmhtxdy/article/details/103923015