青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

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 極限定律 閱讀(1612) 評論(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年5月>
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456

導航

統計

常用鏈接

留言簿(10)

隨筆分類

隨筆檔案

友情鏈接

搜索

最新評論

閱讀排行榜

評論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            亚洲免费观看高清完整版在线观看| 久久综合国产精品| 久久久久久久999| 亚洲自拍16p| 欧美 日韩 国产精品免费观看| 欧美一级片在线播放| 欧美激情第五页| 免费在线视频一区| 国产手机视频一区二区| 一区二区三区精密机械公司| 1769国内精品视频在线播放| 亚洲欧美精品一区| 午夜精品视频在线| 国产精品久久久免费| 日韩亚洲在线观看| 99热在线精品观看| 欧美激情第8页| 亚洲人成高清| 亚洲国产精品久久久久久女王| 欧美一区二区视频免费观看| 亚洲免费影院| 国产精品日本一区二区| 在线中文字幕不卡| 亚洲欧美日韩一区| 国产精品激情电影| 日韩视频免费观看高清在线视频 | 久久亚洲欧洲| 娇妻被交换粗又大又硬视频欧美| 欧美一级专区| 久久先锋资源| 亚洲国产精品一区制服丝袜| 久久最新视频| 亚洲大片免费看| 日韩亚洲欧美综合| 欧美日韩一区二区视频在线观看| 最新国产成人在线观看| 在线亚洲高清视频| 国产精品乱子乱xxxx| 午夜精品久久一牛影视| 久久久精品久久久久| 伊人久久婷婷| 欧美精品一区二区三区一线天视频| 亚洲国产精品久久久久| 一区二区三区**美女毛片| 欧美日韩在线免费| 亚洲欧美另类在线| 老司机一区二区三区| 9色porny自拍视频一区二区| 欧美视频三区在线播放| 亚洲欧美精品在线观看| 麻豆freexxxx性91精品| 99国产精品国产精品久久| 国产精品国产馆在线真实露脸| 亚洲欧美视频在线观看视频| 欧美主播一区二区三区美女 久久精品人| 国产视频一区二区在线观看| 久久综合一区| 夜夜爽99久久国产综合精品女不卡| 香蕉免费一区二区三区在线观看| 国产一区白浆| 欧美连裤袜在线视频| 亚洲新中文字幕| 蜜臀99久久精品久久久久久软件| 99亚洲一区二区| 国产一区二区三区在线观看免费| 免费看精品久久片| 亚洲在线观看免费视频| 欧美成年人网| 欧美在线短视频| 99精品欧美一区二区三区| 国产欧美一区二区三区久久人妖| 美女精品视频一区| 性欧美暴力猛交69hd| 亚洲精品视频在线| 久久综合网络一区二区| 亚洲视频1区| 亚洲国产精品久久久久秋霞不卡| 国产精品免费观看视频| 欧美激情欧美狂野欧美精品| 小辣椒精品导航| 夜夜嗨av一区二区三区| 欧美福利在线| 久久久久久穴| 午夜精品一区二区三区在线视 | 欧美一级播放| 亚洲午夜视频在线| 亚洲精品国产精品国自产观看| 久久午夜羞羞影院免费观看| 亚洲欧美第一页| 9国产精品视频| 亚洲激情自拍| 在线精品观看| 国产一区视频在线看| 国产麻豆视频精品| 欧美视频一区二区三区…| 美女久久一区| 麻豆成人在线观看| 久久久九九九九| 久久er99精品| 久久高清一区| 欧美制服丝袜| 欧美在线视频免费播放| 性8sex亚洲区入口| 性色av一区二区三区在线观看 | 亚洲制服欧美中文字幕中文字幕| 91久久国产综合久久| 亚洲电影在线播放| 欧美高清在线视频| 欧美成人精品三级在线观看 | 欧美成人首页| 欧美成人午夜视频| 欧美国产欧美亚洲国产日韩mv天天看完整 | 久久久久网站| 久久国产精品一区二区三区四区| 亚洲欧美中文日韩v在线观看| 中国女人久久久| 亚洲女同同性videoxma| 亚洲欧美国产va在线影院| 亚洲欧美日韩精品在线| 性久久久久久久久久久久| 午夜免费日韩视频| 久久国产毛片| 欧美成人一区二区三区| 欧美人与性动交α欧美精品济南到 | 欧美另类一区| 国产精品二区在线观看| 国产视频在线观看一区二区| 国产一区二区三区丝袜| 在线免费观看欧美| 99精品免费| 亚洲专区欧美专区| 久久久999成人| 欧美激情a∨在线视频播放| 亚洲精品久久久久久下一站| 亚洲特黄一级片| 久久久99爱| 欧美日韩高清在线| 国产欧美日韩麻豆91| 亚洲国产成人av在线| 亚洲视频免费在线| 久久免费视频在线观看| 亚洲国产一区在线| 亚洲小说春色综合另类电影| 久久精品一区蜜桃臀影院| 欧美www视频在线观看| 国产精品美女黄网| 亚洲福利精品| 欧美一级视频一区二区| 欧美成人精品三级在线观看| 亚洲人成毛片在线播放| 亚洲综合三区| 欧美成人午夜| 国产女同一区二区| 亚洲精品四区| 久久久久青草大香线综合精品| 欧美激情第10页| 性色av一区二区三区| 欧美日韩八区| 在线观看日韩欧美| 午夜亚洲福利| 亚洲精品自在久久| 久久免费视频网站| 国产精品看片资源| 亚洲美女免费视频| 久久蜜桃精品| 亚洲在线免费观看| 欧美日韩国产成人在线91| 悠悠资源网亚洲青| 午夜影院日韩| 一区二区免费看| 欧美精品 日韩| 亚洲大片精品永久免费| 欧美一区二区在线| 9久re热视频在线精品| 欧美xxx成人| 在线成人黄色| 久久婷婷丁香| 久久99伊人| 国产农村妇女精品一区二区| 在线视频你懂得一区| 亚洲国产高清自拍| 久久精品亚洲一区二区| 国产视频精品va久久久久久| 亚洲一区二区三区乱码aⅴ蜜桃女 亚洲一区二区三区乱码aⅴ | 老鸭窝毛片一区二区三区| 亚洲欧美经典视频| 国产精品一区二区三区观看 | 午夜精品视频网站| 亚洲私人影院在线观看| 欧美午夜在线一二页| 在线视频精品一| 日韩一级片网址| 欧美午夜精品久久久| 在线亚洲一区观看| 日韩一二在线观看| 国产精品s色| 午夜视黄欧洲亚洲| 午夜在线视频观看日韩17c| 国产日本欧美在线观看| 久久免费高清|