HDU 4240 Route Redundancy 求一条(流最大)的路径

                                          Route Redundancy

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 913    Accepted Submission(s): 518


 

Problem Description

A city is made up exclusively of one-way steets.each street in the city has a capacity,which is the minimum of the capcities of the streets along that route.

The redundancy ratio from point A to point B is the ratio of the maximum number of cars that can get from point A to point B in an hour using all routes simultaneously,to the maximum number of cars thar can get from point A to point B in an hour using one route.The minimum redundancy ratio is the number of capacity of the single route with the laegest capacity.

 

 

Input

The first line of input contains asingle integer P,(1<=P<=1000),which is the number of data sets that follow.Each data set consists of several lines and represents a directed graph with positive integer weights.

The first line of each data set contains five apace separatde integers.The first integer,D is the data set number. The second integer,N(2<=N<=1000),is the number of nodes inthe graph. The thied integer,E,(E>=1),is the number of edges in the graph. The fourth integer,A,(0<=A<N),is the index of point A.The fifth integer,B,(o<=B<N,A!=B),is the index of point B.

The remaining E lines desceibe each edge. Each line contains three space separated in tegers.The First integer,U(0<=U<N),is the index of node U. The second integer,V(0<=v<N,V!=U),is the node V.The third integer,W (1<=W<=1000),is th capacity (weight) of path from U to V.

 

 

Output

For each data set there is one line of output.It contains the date set number(N) follow by a single space, followed by a floating-point value which is the minimum redundancy ratio to 3 digits after the decimal point.

 

 

Sample Input

 

1 1 7 11 0 6 0 1 3 0 3 3 1 2 4 2 0 3 2 3 1 2 4 2 3 4 2 3 5 6 4 1 1 4 6 1 5 6 9

 

 

Sample Output

 

1 1.667

 

 

Source

2011 Greater New York Regional

 

 

Recommend

We have carefully selected several similar problems for you:  4236 4237 4238 4239 4241 

 

求一条(流最大)的路径  等价于  可行流路径上的最小容量”的最大值maxmincap

 

//Max_flow
//@2018/05/02 Wednesday
//EK algorithm [Edmonds Karp] O(V*E^2) O(v^2)
//by Tawn
#include <bits/stdc++.h>

using namespace std;
const int maxn = 1e3+10;
const int INF = 0x3f3f3f3f;

int n,m; //n - Vertices  m - edges
int pre[maxn]; //record predecesor and sign if it is visited
int cap[maxn][maxn]; //record the capacity of residual network
int capp[maxn][maxn];
int flow[maxn]; //record the residual flow from starting vertex to current vertex
queue <int> q;

int maxv;

int bfs(int st, int ed)
{
  memset(pre,-1,sizeof(pre));
  while(!q.empty()) q.pop();
  pre[st] = 0;
  flow[st] = INF;
  q.push(st);
  while(!q.empty())
  {
    int t = q.front();
    q.pop();
    if(t == ed) break;
    for(int i = 1; i <= n; i++)
    {
        if(pre[i] == -1 && cap[t][i] > 0)
        {
            pre[i] = t;
            flow[i] = min(flow[t],cap[t][i]);
            q.push(i);
        }
    }
  }
  if(pre[ed] == -1)  return -1;
  else              return flow[ed];
}


int EK(int st, int ed)
{
    int res = 0; //the augmenting flow
    int sum = 0; //the max_flow
    while((res = bfs(st,ed)) != -1)//argumenting path
    {
        int k = ed;
        int minc = INF;
        while(k != st)
        {
            int f = pre[k];
            minc = min(minc,capp[f][k]);
            cap[f][k] -= res;
            cap[k][f] += res;//reversible edge
            k = f;
        }
        sum += res;
        maxv = max(maxv,minc);
    }
    return sum;
}


int D,N,E,A,B;

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
    scanf("%d%d%d%d%d",&D,&N,&E,&A,&B);
    n = N;
    m = E;
    int s,t,c;
   memset(cap,0,sizeof(cap));
   memset(capp,0,sizeof(capp));
   for(int i = 0; i < m; i++)
   {
    scanf("%d%d%d",&s,&t,&c);
    s++,t++;
    cap[s][t] += c;
    capp[s][t] += c;
   }
   maxv = -INF;
   int ans = EK(A+1,B+1);
   printf("%d %.3lf\n",D,(double)ans/(double)maxv);
   }
   return 0;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值