zoukankan      html  css  js  c++  java
  • Codevs 1993 草地排水

    1993 草地排水

    时间限制: 2 s    空间限制: 256000 KB    题目等级 : 钻石 Diamond
    题目描述 Description

    在农夫约翰的农场上,每逢下雨,Bessie最喜欢的三叶草地就积聚了一潭水。这意味着草地被水淹没了,并且小草要继续生长还要花相当长一段时间。因此,农夫约翰修建了一套排水系统来使贝茜的草地免除被大水淹没的烦恼(不用担心,雨水会流向附近的一条小溪)。作为一名一流的技师,农夫约翰已经在每条排水沟的一端安上了控制器,这样他可以控制流入排水沟的水流量。

    农夫约翰知道每一条排水沟每分钟可以流过的水量,和排水系统的准确布局(起点为水潭而终点为小溪的一张网)。需要注意的是,有些时候从一处到另一处不只有一条排水沟。

    根据这些信息,计算从水潭排水到小溪的最大流量。对于给出的每条排水沟,雨水只能沿着一个方向流动,注意可能会出现雨水环形流动的情形。

    输入描述 Input Description

    第1行: 两个用空格分开的整数N (0 <= N <= 200) 和 M (2 <= M <= 200)。N是农夫John已经挖好的排水沟的数量,M是排水沟交叉点的数量。交点1是水潭,交点M是小溪。

    第二行到第N+1行: 每行有三个整数,Si, Ei, 和 Ci。Si 和 Ei (1 <= Si, Ei <= M) 指明排水沟两端的交点,雨水从Si 流向Ei。Ci (0 <= Ci <= 10,000,000)是这条排水沟的最大容量。

    输出描述 Output Description

    输出一个整数,即排水的最大流量。

    样例输入 Sample Input
    5 4
    1 2 40
    1 4 20
    2 4 20
    2 3 30
    3 4 10
    样例输出 Sample Output

    50

     1 #include<queue>
     2 #include<vector>
     3 #include<cstring>
     4 #include<iostream>
     5 #include<cstdio>
     6 using namespace std;
     7 #define INF 0x7f
     8 int n,m,map[205][205]={0},lays[205];
     9 bool vis[205];
    10 bool BFS(){
    11     queue<int>q;
    12     memset(lays,-1,sizeof(lays));
    13     lays[1]=0;q.push(1);
    14     while(!q.empty()){
    15         int u=q.front();q.pop();
    16         for(int i=1;i<=m;i++){
    17             if(map[u][i]>0&&lays[i]==-1){
    18                 lays[i]=lays[u]+1;
    19                 if(i==m)return 1;
    20                 else q.push(i);
    21             }
    22         }
    23     }
    24     return 0;
    25 }
    26 int Dinic(){
    27     int maxf=0;vector<int>st;
    28     while(BFS()){
    29         st.push_back(1);
    30         memset(vis,0,sizeof(vis));vis[1]=1;
    31         while(!st.empty()){
    32             int p=st.back();
    33             if(p==m){
    34                 int minn,minx=INF;
    35                 for(int i=1;i<st.size();i++){
    36                     int u=st[i-1],v=st[i];
    37                     if(map[u][v]>0&&map[u][v]<minx){
    38                         minn=u;minx=map[u][v];
    39                     }
    40                 }
    41                 maxf+=minx;
    42                 for(int i=1;i<st.size();i++){
    43                     int u=st[i-1],v=st[i];
    44                     map[u][v]-=minx;
    45                     map[v][u]+=minx;
    46                 }
    47                 while(!st.empty()&&st.back()!=minn){
    48                     vis[st.back()]=0;st.pop_back();
    49                 }
    50             }
    51             else {
    52                 int i;
    53                 for(i=1;i<=m;i++){
    54                     if(map[p][i]>0&&lays[i]==
    55                        lays[p]+1&&!vis[i]){
    56                             vis[i]=1;st.push_back(i);
    57                             break;
    58                        }
    59                 }
    60                 if(i>m)st.pop_back();
    61             }
    62         }
    63     }
    64     return maxf;
    65 }
    66 int main()
    67 {
    68     scanf("%d%d",&n,&m);
    69     for(int i=1,a,b,c;i<=n;i++){
    70         scanf("%d%d%d",&a,&b,&c);
    71         map[a][b]+=c;
    72     }
    73     printf("%d
    ",Dinic());
    74     return 0;
    75 }
  • 相关阅读:
    Enterprise Library 3.0 – April 2007 Released
    Static methods can not be called remotely
    BizTalk: 提高 BizTalk 编程能力的 8 点技巧和窍门(MSDN Magazine)
    Calling Stored Procedures Using the SQL Adapter
    BizTalk: Difference between (PassThruReceive, PassThruSend) and (XmlReceive, XmlSend) Biztalk Pipelines (For Beginners)
    BizTalk Exception: Cannot access a disposed object && Failed to serialize the message part "BankQuoteRequest" into the type "BankQuoteRequest"
    Oneway web service call in BizTalk Orchestration
    Create route in crossserver SSB
    BizTalk: PublisherSubscriber model and Binding
    BizTalk Exception: Calling web services with Mixed OneWay and SolicitResponse Operations
  • 原文地址:https://www.cnblogs.com/suishiguang/p/6481102.html
Copyright © 2011-2022 走看看