• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            #include <iostream>
            #include 
            <queue>
            #include 
            <algorithm>
            #include 
            <climits>

            using  namespace std;

            #define N  210

            int  point, edge;
            int  graph[N][N];
            int  pre[N];
            int  result= 0;

            void update( int mflow )
            {
                
            int b= point;
                
                result
            += mflow;
                
            while( pre[b]!= 0 )
                
            {
                    graph[ pre[b] ][ b]
            -= mflow;
                    graph[b ][ pre[b] ]
            += mflow;
                    
                    b
            = pre[b];
                }
                
            }


            void bfs()
            {
                
            whiletrue )
                
            {
                    
            bool visite[N]= false };
                    
            int  minflow[N];
                    queue
            <int>  q;
                    
                    q.push( 
            1 );
                    visite[
            1]= true;
                    minflow[
            1]= INT_MAX;
                    memset( pre, 
            0sizeof(pre) );
                    
                    
            while!q.empty() )
                    
            {
                        
            int t= q.front();
                        q.pop();
                        
                        
            forint j= 1; j<= point; ++j )
                            
            if!visite[j] && graph[t][j]> 0 )
                            
            {
                                minflow[j]
            = min( minflow[t], graph[t][j] );
                                pre[j]
            = t;
                                
                                q.push( j );
                                visite[j]
            = true;
                            }

                        
                        
            if( pre[point]> 0 ) break;
                    }

                    
                    
            if ( pre[point]> 0 )  update( minflow[point] );
                    
            else                  break;
                }

            }


            int main()
            {
                
            while( scanf("%d%d"&edge, &point )!= EOF )
                
            {
                    memset( graph, 
            0sizeof(graph) );
                    
                    
            forint i= 0; i< edge; ++i )
                    
            {
                        
            int a, b, d;
                        scanf(
            "%d%d%d"&a, &b, &d );
                        
                        graph[a][b]
            += d;    //   not just one ditch
                    }

                    
                    result
            = 0;
                    bfs();
                    printf(
            "%d\n", result );
                }

                
                
            return 0;
            }




            #include <stdio.h>
            #include 
            <stdlib.h>
            #include 
            <string.h>

            #define Min(a,b) ( (a)< (b)?(a): (b) )

            int  m, n;
            int  map[210][210];
            bool visite[210];
            int  path[210], dist[210], minflow[210];

            int max_flow()
            {
                
            forint i= 0; i<= n; ++i )
                {
                    visite[i]
            = false;    dist[i]= 0;
                    path[i]
            = 1;          minflow[i]= 0;
                }
                
                visite[
            1]= true;   minflow[1]= 1<< 30;
                
            forint i= 1; i<= n; ++i )
                dist[i]
            = map[1][i], minflow[i]= map[1][i];
                
                
            forint i= 1; i< n; ++i )
                {
                    
            int min= 1<< 30, t= -1;
                    
                    
            forint j= 1; j<= n; j++ )
                    
            if!visite[j] && min> dist[j] && dist[j]> 0 ) min= dist[j],t= j;
                    
                    
            if( t== -1 ) break;
                    
                    visite[t]
            = true;
                    
            forint j= 1; j<= n; ++j )
                        
            if!visite[j] && map[t][j]> 0 && 
                           ( dist[t]
            > 0 && dist[t]+ map[t][j]< dist[j] || dist[j]== 0 ) )
                        {
                            dist[j]
            = dist[t]+ map[t][j];
                            path[j]
            = t;
                            
                            minflow[j]
            = Min( map[t][j], minflow[t] );
                        }
                }
                
                
            return minflow[n];
            }

            int update()
            {
                
            int f, total= 0;
                
                
            while( ( f= max_flow() )!= 0 )
                {
                    
            int j= n;
                    
                    
            while( path[j]!= j )
                    {
                        map[ path[j] ][j]
            -= f;
                        map[j][ path[j] ]
            += f;
                        
                        j
            = path[j];
                    }
                    
                    total
            += f;
                }
                
                
            return total;
            }

            int main()
            {
                
            while( scanf("%d%d",&m,&n)!= EOF )
                {
                    memset( map, 
            0sizeof(map) );
                    
                    
            forint i= 0; i< m; ++i )
                    {
                        
            int a, b, c;
                        scanf(
            "%d%d%d",&a,&b,&c);
                        
                        map[a][b]
            += c;
                    }
                    
                    printf(
            "%d\n", update() );
                }
                
                
            return 0;
            }



            #include <iostream>
            #include 
            <queue>
            #include 
            <algorithm>

            using namespace std;

            int  m, n;
            int  map[210][210], h[210],wt[210], flow[210][210];

            int max_flow()
            {
                memset( wt, 
            0sizeof(wt) );
                memset( h, 
            0sizeof(h) );
                
                queue
            <int> Q;
                Q.push(
            1); wt[1]= 1<<30; wt[n]= -1<<30;
                h[
            1]= n;
                
                
            int total= 0;
                
            while!Q.empty() )
                {
                    
            int u= Q.front(); Q.pop();
                    
                    
            forint v= 1; v<= n; ++v )
                    {
                        
            int f= min( wt[u], map[u][v] );
                        
                        
            if( f> 0 &&  ( u== 1 || h[u]== h[v]+ 1 ) )
                        {
                            map[u][v]
            -= f, map[v][u]+= f;
                            wt[u]
            -= f, wt[v]+= f;
                            
                            
            if( v== n ) total+= f;
                            
                            
            if( v!= 1 && v!= n ) Q.push(v);
                        }
                    }            
                    
                    
            if( u!= 1 && u!= n && wt[u]> 0 )
                    {
                        h[u]
            ++;
                        Q.push(u);
                    }
                }
                
                printf(
            "%d\n", total );
            }
                
            int main()
            {
                
            while( scanf("%d%d",&m,&n)!= EOF )
                {
                    memset( map, 
            0sizeof(map) );
                    
                    
            forint i= 0; i< m; ++i )
                    {    
                        
            int a, b, c;
                        
                        scanf(
            "%d%d%d",&a,&b,&c);
                        map[a][b]
            += c;
                    }
                    
                    max_flow();
                }
                
                
            return 0;
            }
            posted on 2008-11-04 14:15 Darren 閱讀(216) 評論(1)  編輯 收藏 引用

            評論:
            # re: Pku 1273 Drainage Ditches 2009-01-12 12:02 | 風之傷
            謝謝大牛,寫得很清晰,受教了~~  回復  更多評論
              
            久久天天躁狠狠躁夜夜av浪潮 | 久久精品视频网| 成人久久精品一区二区三区| 国产精品激情综合久久| 欧美午夜精品久久久久免费视| 久久久老熟女一区二区三区| 国产成人无码精品久久久免费| 久久亚洲AV成人出白浆无码国产| 91精品国产9l久久久久| 成人午夜精品久久久久久久小说| 一级做a爰片久久毛片毛片| 国产—久久香蕉国产线看观看| 久久国产精品二国产精品| 久久精品国产99国产电影网| 思思久久99热免费精品6| 国产成人精品久久亚洲高清不卡 | 中文国产成人精品久久亚洲精品AⅤ无码精品 | 久久国产精品99国产精| 久久一区二区免费播放| 成人国内精品久久久久影院| 久久久久久久综合狠狠综合| 久久午夜福利电影| 久久本道伊人久久| 久久人人爽人人爽人人片AV不 | 久久久一本精品99久久精品88| 久久久久综合网久久| 久久精品男人影院| 国产精品久久久久AV福利动漫| A狠狠久久蜜臀婷色中文网| 思思久久精品在热线热| 久久综合亚洲欧美成人| 久久中文字幕精品| 欧洲国产伦久久久久久久| 99久久精品免费看国产| 久久综合五月丁香久久激情| 国产成人无码久久久精品一| 亚洲国产精品无码久久| 夜夜亚洲天天久久| 国产精品成人99久久久久91gav| 国产成人久久精品二区三区| 精品久久久久久无码国产|