poj 3308 Paratroopers

http://poj.org/problem?id=3308

 1 #include <cstdio>

 2 #include <cstring>

 3 #include <algorithm>

 4 #include <queue>

 5 #include <cmath>

 6 #define maxn 10000

 7 using namespace std;

 8 

 9 const int inf=1<<30;

10 int n,m,l,x,y;

11 double c,f;

12 double cap[200][200],flow[200][200];

13 int p[200];

14 double a[200];

15 

16 void EK(int s)

17 {

18    queue<int>q;

19    memset(flow,0,sizeof(flow));

20    f=0;

21    for(; ;)

22    {

23        memset(a,0,sizeof(a));

24        memset(p,-1,sizeof(p));

25        a[s]=inf;

26        q.push(s);

27        while(!q.empty())

28        {

29            int u=q.front();

30            q.pop();

31            for(int v=0; v<=m+n+1; v++)

32            {

33                if(!a[v]&&cap[u][v]>flow[u][v])

34                {

35                    p[v]=u;

36                    q.push(v);

37                    a[v]=min(a[u],cap[u][v]-flow[u][v]);

38                }

39            }

40        }

41        if(a[m+n+1]==0) break;

42        for(int u=m+n+1; u!=0; u=p[u])

43        {

44            flow[p[u]][u]+=a[m+n+1];

45            flow[u][p[u]]-=a[m+n+1];

46        }

47        f+=a[m+n+1];

48    }

49 }

50 

51 int main()

52 {

53     int T;

54     scanf("%d",&T);

55     while(T--)

56     {

57         memset(cap,0,sizeof(cap));

58         scanf("%d%d%d",&m,&n,&l);

59         for(int i=1;i<=m; i++)

60         {

61             scanf("%lf",&c);

62             cap[0][i]=log(c);

63         }

64         for(int i=m+1; i<=m+n; i++)

65         {

66             scanf("%lf",&c);

67             cap[i][m+n+1]=log(c);

68         }

69         for(int i=0; i<l; i++)

70         {

71             scanf("%d%d",&x,&y);

72             cap[x][m+y]=inf;

73         }

74         f=0;

75         EK(0);

76         printf("%.4f\n",exp(f));

77     }

78     return 0;

79 }
View Code

 

你可能感兴趣的:(oop)