1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
| #include "iostream" #include "algorithm" #include "cstring" #include "cstdio" #include "cmath" #include "vector" #include "map" #include "set" #include "queue" #include "assert.h"
using namespace std; #define MAXN 200006
#define rep( i , a , b ) for (int i = (a), i##end = (b); i <= i##end; ++i) #define per( i , a , b ) for (int i = (a), i##end = (b); i >= i##end; --i) #define pii pair<int,int> #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define vi vector<int> #define all( x ) (x).begin() , (x).end() #define mem( a ) memset( a , 0 , sizeof a ) typedef long long ll; #define P 998244353
int n , s , t; int head[MAXN] , to[MAXN << 1] , nex[MAXN << 1] , wto[MAXN << 1] , cto[MAXN << 1] , ecn = -1;
void ade( int u , int v , int w , int c ) {
to[++ecn] = v , nex[ecn] = head[u] , wto[ecn] = w , head[u] = ecn , cto[ecn] = c; to[++ecn] = u , nex[ecn] = head[v] , wto[ecn] = 0 , head[v] = ecn , cto[ecn] = -c; }
queue<int> Q; int dis[MAXN] , pre[MAXN] , vis[MAXN]; const int inf = 1e9;
bool spfa( int s ) { mem( vis ); Q.push( s ); memset( dis , 0x3f , sizeof dis ); memset( pre , -1 , sizeof pre ); dis[s] = 0 , vis[s] = 1; while( !Q.empty( ) ) { int u = Q.front( ); Q.pop( ); vis[u] = 0; for( int i = head[u] ; ~i ; i = nex[i] ) if( wto[i] && dis[to[i]] > dis[u] + cto[i] ) { int v = to[i]; dis[v] = dis[u] + cto[i]; pre[v] = i; if( !vis[v] ) Q.push( v ) , vis[v] = 1; } } return pre[t] != -1; }
vector<pii> fc; int flow , co; void doit( ) { int T = t , fl = 0x3f3f3f3f; while( ~pre[T] ) fl = min( fl , wto[pre[T]] ) , T = to[pre[T] ^ 1]; flow += fl , co += fl * dis[t]; fc.eb( mp( flow , co ) ); T = t; while( ~pre[T] ) wto[pre[T]] -= fl , wto[pre[T] ^ 1] += fl , T = to[pre[T] ^ 1]; }
void mcmf( ) { flow = co = 0; while( spfa( s ) ) doit( ); }
void solve( ) { memset( head , -1 , sizeof head ); int n , m; cin >> n >> m; ::n = n; s = 1 , t = n; rep( i , 1 , m ) { static int u , v , w; scanf("%d%d%d",&u,&v,&w) , ade( u , v , 1 , w ); } mcmf( ); int q;cin >> q; double re; while( q-- ) { static int x; re = 1e9; scanf("%d",&x); for( auto& t : fc ) re = min( re , 1. * ( t.se + x ) / t.fi ); printf("%.8lf\n",re); } }
signed main( ) {
solve( ); }
|