• <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>

            POJ 3352 Road Construction 雙連通分量+縮點

            Description

            It's almost summer time, and that means that it's almost summer construction time! This year, the good people who are in charge of the roads on the tropical island paradise of Remote Island would like to repair and upgrade the various roads that lead between the various tourist attractions on the island.

            The roads themselves are also rather interesting. Due to the strange customs of the island, the roads are arranged so that they never meet at intersections, but rather pass over or under each other using bridges and tunnels. In this way, each road runs between two specific tourist attractions, so that the tourists do not become irreparably lost.

            Unfortunately, given the nature of the repairs and upgrades needed on each road, when the construction company works on a particular road, it is unusable in either direction. This could cause a problem if it becomes impossible to travel between two tourist attractions, even if the construction company works on only one road at any particular time.

            So, the Road Department of Remote Island has decided to call upon your consulting services to help remedy this problem. It has been decided that new roads will have to be built between the various attractions in such a way that in the final configuration, if any one road is undergoing construction, it would still be possible to travel between any two tourist attractions using the remaining roads. Your task is to find the minimum number of new roads necessary.

            Input

            The first line of input will consist of positive integers n and r, separated by a space, where 3 ≤ n ≤ 1000 is the number of tourist attractions on the island, and 2 ≤ r ≤ 1000 is the number of roads. The tourist attractions are conveniently labelled from 1 to n. Each of the following r lines will consist of two integers, v and w, separated by a space, indicating that a road exists between the attractions labelled v and w. Note that you may travel in either direction down each road, and any pair of tourist attractions will have at most one road directly between them. Also, you are assured that in the current configuration, it is possible to travel between any two tourist attractions.

            Output

            One line, consisting of an integer, which gives the minimum number of roads that we need to add.

            Sample Input

            Sample Input 1
            10 12
            1 2
            1 3
            1 4
            2 5
            2 6
            5 6
            3 7
            3 8
            7 8
            4 9
            4 10
            9 10
            Sample Input 2
            3 3
            1 2
            2 3
            1 3

            Sample Output

            Output for Sample Input 1
            2
            Output for Sample Input 2
            0
            

            Source


               

                題目大意:給定一個雙向連通的公路網,當某些公路路段檢修的時候可能會由于該段公路不通,可能會使某些旅游點之間無法通行,求至少新建多少條公路,使得任意對一段公路進行檢修的時候,所有的旅游景點之間仍然暢通;

                分析:檢修某一路段導致公路網不暢通的原因必然是該段公路在圖中是橋(割邊),因此完全暢通的方法就是,加最若干條邊,使圖中不存在橋。先找出圖中所有的雙連通分量,將雙連通分量進行縮點,得到一個樹形圖,求出這個樹形圖中度為1的點的個數,新加邊的條數即是(度為1的點數目+1)/2,考慮到題目只要求求度為1的點數目,因此可以部分縮點,利用并查集,保存每個割邊的頂點,統計每個頂點在并查集中的代表元的度數即可。
                Sample 1中存在4個雙連通分量:{1},{2,5,6},{3,7,8},{4,9,10},進行縮點之后,求得一個4個節點的樹形圖,其中一個點的度數為3,其余3個點的度數為1,得到需要加的邊的數目為(3+1)/2=2。

            #include <iostream>
            #include 
            <vector>
            using namespace std;

            const int MAXN = 5001;
            vector
            < vector<int> > adj;
            int cnt,low[MAXN],pre[MAXN],visit[MAXN],degree[MAXN];

            void dfs(int u,int v){
                visit[u]
            =1;
                pre[u]
            =cnt++,low[u]=pre[u];
                
            int i,len=adj[u].size();
                
            for(i=0;i<len;i++){
                    
            if(adj[u][i]==v) continue;
                    
            if(!visit[adj[u][i]]) dfs(adj[u][i],u);
                    
            if(low[adj[u][i]]<low[u]) low[u]=low[adj[u][i]];
                }

                visit[u]
            =2;
            }

            int main(){
                
            int i,j,u,v,n,m,len,ans;
                scanf(
            "%d %d",&n,&m);
                adj.assign(n
            +1,vector<int>());
                
            while(m--){
                    scanf(
            "%d %d",&u,&v);
                    adj[u].push_back(v),adj[v].push_back(u);
                }

                memset(visit,
            0,sizeof(visit));
                cnt
            =0,dfs(1,1);
                memset(degree,
            0,sizeof(degree));
                
            for(i=1;i<=n;i++){
                    len
            =adj[i].size();
                    
            for(j=0;j<len;j++)
                        
            if(low[i]!=low[adj[i][j]])
                            degree[low[i]]
            ++;
                }

                
            for(ans=i=0;i<=n;i++)
                    
            if(degree[i]==1) ans++;
                printf(
            "%d\n",(ans+1)/2);
                
            return 0;
            }

            posted on 2009-05-29 18:53 極限定律 閱讀(1573) 評論(3)  編輯 收藏 引用 所屬分類: ACM/ICPC

            評論

            # re: POJ 3352 Road Construction 雙連通分量+縮點 2009-08-03 10:47 路人

            11 14
            1 2
            1 3
            1 4
            2 5
            6 11
            2 6
            5 6
            5 11
            3 7
            3 8
            7 8
            4 9
            4 10
            9 10

            你的程序,這組數據時錯誤的。。  回復  更多評論   

            # re: POJ 3352 Road Construction 雙連通分量+縮點 2009-08-04 09:46 mythit

            @路人
            多謝指正  回復  更多評論   

            # re: POJ 3352 Road Construction 雙連通分量+縮點 2011-07-25 19:14 過客

            void dfs(int u,int v){
            visit[u]=1;
            pre[u]=cnt++,low[u]=pre[u];
            int i,len=adj[u].size();
            for(i=0;i<len;i++){
            if(adj[u][i]==v) continue;
            if(!visit[adj[u][i]]) dfs(adj[u][i],u);
            if(low[adj[u][i]]<low[u]) low[u]=low[adj[u][i]];
            }
            visit[u]=2;
            }
            最后一句 visit[u]=2;有什么用啊,求解釋  回復  更多評論   

            <2009年4月>
            2930311234
            567891011
            12131415161718
            19202122232425
            262728293012
            3456789

            導航

            統計

            常用鏈接

            留言簿(10)

            隨筆分類

            隨筆檔案

            友情鏈接

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            狠狠精品久久久无码中文字幕 | 伊人久久大香线蕉影院95| 精品熟女少妇AV免费久久| 欧美午夜精品久久久久免费视 | 亚洲精品乱码久久久久久蜜桃不卡| 狠狠色婷婷久久综合频道日韩| AV狠狠色丁香婷婷综合久久| 狠狠色伊人久久精品综合网| 中文字幕乱码人妻无码久久| 99久久精品免费| 亚洲国产精品久久久天堂| 久久综合欧美成人| 婷婷伊人久久大香线蕉AV| 国产精品综合久久第一页| 精品久久久久久中文字幕人妻最新| 久久综合九色综合久99 | 国内精品久久久久久久97牛牛 | 免费久久人人爽人人爽av| 久久亚洲精品视频| 亚洲午夜久久久影院伊人| 久久精品国产99久久久香蕉| 1000部精品久久久久久久久| 久久无码国产专区精品| 狠狠人妻久久久久久综合| 99国产精品久久久久久久成人热| 少妇被又大又粗又爽毛片久久黑人| 婷婷综合久久狠狠色99h| 亚洲欧美日韩中文久久| 午夜精品久久久久久久无码| 久久精品国产色蜜蜜麻豆| 久久最近最新中文字幕大全| 97热久久免费频精品99| 中文字幕久久久久人妻| 精品伊人久久大线蕉色首页| 思思久久精品在热线热| 久久精品国产男包| 伊人久久无码中文字幕| 亚洲AV无码1区2区久久| 久久天天躁狠狠躁夜夜躁2O2O| 久久精品国产亚洲av麻豆蜜芽| 亚洲中文久久精品无码|