"Problem Analysis"
It is easy to think that it is best to put p on the edge of the maximum flow.
So two-point network flow, determine when the maximum flow can be reached.
Traffic is not necessarily an integer, so a real number is required, and the integer is WA.
Code
#include <cstdio> #include <cstring> #include <cmath> #include <cstdlib>//#include <map> #include <set> #include <queue> #include <string> #include <iostream> #include <algorithm >using namespace std; #define MAXN 1005#define me 50005#define inf 0x3f3f3f3f#define F (I,J,K) for (int i=j;i<=k;++i) # Define D (I,j,k) for (int i=j;i>=k;--i) #define EPS 1e-8void finout () {#ifndef Online_judge freopen ("In.txt", "R", St DIN);//Freopen ("OUT.txt", "w", stdout); #endif}int Getint () {int x=0,f=1; char Ch=getchar (); while (ch< ' 0 ' | | Ch> ' 9 ') {if (ch== '-') f=-1; Ch=getchar ();} while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} return x*f;} int h[me],to[me<<1],ne[me<<1];d ouble fl[me<<1];int en=0,s=0,t=me-1;int Lim[me]; void Add (int a,int b,double c) {//cout<<a<< "" <<b<< "" <<c<<endl; To[en]=b; Ne[en]=h[a]; Fl[en]=c; h[a]=en++; To[en]=a; NE[EN]=H[B]; Fl[En]=0; h[b]=en++;} int map[maxn],tag=0; BOOL Tell () {queue <int> q; memset (map,-1,sizeof map); map[s]=0; Q.push (S); while (!q.empty ()) {int X=q.front (); Q.pop (); for (int i=h[x];i>=0;i=ne[i]) {if (map[to[i]]==-1&&fl[i]>eps) { map[to[i]]=map[x]+1; Q.push (To[i]); }}} if (Map[t]!=-1) return true; return false;} Double Zeng (int k,double R) {if (k==t) return R; Double ret=0; for (int i=h[k];i>=0&&ret<r;i=ne[i]) if (map[to[i]]==map[k]+1&&fl[i]>eps) { Double Tmp=zeng (To[i],min (Fl[i], (double) r-ret)); ret+=tmp; fl[i]-=tmp; fl[i^1]+=tmp; } if (!ret) map[k]=-1; return ret;} int N,a[maxn],b[maxn],c[maxn],m,p;int Main () {finout (); memset (h,-1,sizeof h); N=getint (); M=getint (); P=getint (); S=1; T=n; int maxx=0; F (i,1,m) {a[i]=getint (); B[i]=getint (); C[i]=getint (); Add (A[i],b[i], (double) c[i]); Maxx=max (C[i],maxx);} Double Ans=0,tmp;while (Tell ()) while (Tmp=zeng (S, (double) inf)) Ans+=tmp;cout<<ans+eps<<endl;double l=0, R= (Double) maxx;while (l+eps<r) {//cout<<l<< "" <<r<<endl;double mid= (l+r)/2;en=0;memset ( H,-1,sizeof h); F (i,1,m) Add (A[i],b[i],min (Mid, (double) c[i]));d ouble Now=0,tmp;while (Tell ()) while (Tmp=zeng (S, (double) inf)) now+= Tmp;if (Fabs (Now-ans) <=eps) R=mid;else L=mid;} printf ("%.5f\n", l*p);}
Bzoj 3130 [Sdoi2013] Cost Flow--network flow