• <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>
            posts - 7,comments - 3,trackbacks - 0
            Minimum Cut
            Time Limit: 10000MSMemory Limit: 65536K
            Total Submissions: 5403Accepted: 2113
            Case Time Limit: 5000MS

            Description

            Given an undirected graph, in which two vertices can be connected by multiple edges, what is the size of the minimum cut of the graph? i.e. how many edges must be removed at least to disconnect the graph into two subgraphs?

            Input

            Input contains multiple test cases. Each test case starts with two integers N and M (2 ≤ N ≤ 500, 0 ≤ M ≤ N × (N − 1) ⁄ 2) in one line, where N is the number of vertices. Following are M lines, each line contains M integers AB and C (0 ≤ AB < NA ≠ BC > 0), meaning that there C edges connecting vertices A and B.

            Output

            There is only one line for each test case, which contains the size of the minimum cut of the graph. If the graph is disconnected, print 0.

            Sample Input

            3 3
            0 1 1
            1 2 1
            2 0 1
            4 3
            0 1 1
            1 2 1
            2 3 1
            8 14
            0 1 1
            0 2 1
            0 3 1
            1 2 1
            1 3 1
            2 3 1
            4 5 1
            4 6 1
            4 7 1
            5 6 1
            5 7 1
            6 7 1
            4 0 1
            7 3 1

            Sample Output

            2
            1
            2

            Source

            Baidu Star 2006 Semifinal 
            Wang, Ying (Originator) 
            Chen, Shixi (Test cases)

            全局最小割,模板題,Stor-Wagner算法,大概就是prime的最大生成樹,具體的網上有很多,可以google到的,不多說了。
            代碼:
            #include<stdio.h>
            #include<string.h>

            #define NN 504
            #define INF 1 << 30
            int vis[NN];
            int wet[NN];
            int combine[NN];
            int map[NN][NN];

            int S, T, minCut, N;
            void Search()
            {
                
            int i, j, Max, tmp;
                memset(vis, 
            0sizeof(vis));
                memset(wet, 
            0sizeof(wet));
                S 
            = T = -1;
                
            for (i = 0; i < N; i++)
                {
                    Max 
            = -INF;
                    
            for (j = 0; j < N; j++)
                    {
                        
            if (!combine[j] && !vis[j] && wet[j] > Max)
                        {
                            tmp 
            = j;
                            Max 
            = wet[j];
                        }
                    }
                    
            if (T == tmp) return;
                    S 
            = T;
                    T 
            = tmp;
                    minCut 
            = Max;
                    vis[tmp] 
            = 1;
                    
            for (j = 0; j < N; j++)
                    {
                        
            if (!combine[j] && !vis[j])
                        {
                            wet[j] 
            += map[tmp][j];
                        }
                    }
                }
            }
            int Stoer_Wagner()
            {
                
            int i, j;
                memset(combine, 
            0sizeof(combine));
                
            int ans = INF;
                
            for (i = 0; i < N - 1; i++)
                {
                    Search();
                    
            if (minCut < ans) ans = minCut;
                    
            if (ans == 0return 0;
                    combine[T] 
            = 1;
                    
            for (j = 0; j < N; j++)
                    {
                        
            if (!combine[j])
                        {
                            map[S][j] 
            += map[T][j];
                            map[j][S] 
            += map[j][T];
                        }
                    }
                }
                
            return ans;
            }
            int main()
            {
                
            int a, b, c, M;
                
            while(scanf("%d%d"&N, &M) != EOF)
                {
                    memset(map, 
            0sizeof(map));
                    
            while(M--)
                    {
                        scanf(
            "%d%d%d"&a, &b, &c);
                        map[a][b] 
            += c;
                        map[b][a] 
            += c;
                    }
                    printf(
            "%d\n", Stoer_Wagner());
                }
                
            return 0;
            }
            posted on 2011-10-15 22:10 LLawliet 閱讀(220) 評論(0)  編輯 收藏 引用 所屬分類: 網絡流
            人人狠狠综合久久亚洲婷婷| 久久人人爽人人爽人人片AV东京热| 一本色综合网久久| 久久伊人精品青青草原日本| 99蜜桃臀久久久欧美精品网站| 2021久久国自产拍精品| 久久久久亚洲AV无码专区网站 | 精品久久久久中文字幕一区| 精品国产日韩久久亚洲| 国内精品久久国产大陆| 亚洲精品tv久久久久| 久久精品嫩草影院| 一本一本久久a久久综合精品蜜桃 一本一道久久综合狠狠老 | 一级做a爰片久久毛片16| 久久久久久久波多野结衣高潮 | 四虎国产精品免费久久| 99久久成人国产精品免费| 亚洲午夜福利精品久久| 国产成人精品久久一区二区三区av| 怡红院日本一道日本久久| 中文精品久久久久人妻不卡| 亚洲国产日韩欧美综合久久| 日韩一区二区三区视频久久| 伊人热人久久中文字幕| 国产精品美女久久久久网| 亚洲国产精品无码久久久蜜芽| 性高朝久久久久久久久久| 人妻无码精品久久亚瑟影视| 久久九九免费高清视频| 久久夜色tv网站| 久久96国产精品久久久| 国产韩国精品一区二区三区久久| 久久99精品久久久久久hb无码| 亚洲狠狠婷婷综合久久久久| 精品人妻伦九区久久AAA片69| 久久成人小视频| 色播久久人人爽人人爽人人片AV| 久久亚洲国产最新网站| 久久无码AV一区二区三区| 思思久久99热只有频精品66| 久久久久久精品免费免费自慰|