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

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 極限定律 閱讀(1603) 評論(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年8月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
303112345

導航

統計

常用鏈接

留言簿(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>
            亚洲第一页自拍| 亚洲欧美日韩综合一区| 亚洲网站在线| 亚洲欧美综合v| 久久久www成人免费精品| 久久久久久夜精品精品免费| 久久久久欧美精品| 欧美激情综合色| 99视频精品| 久久精品卡一| 欧美日韩一视频区二区| 国产精品亚洲欧美| 亚洲国产影院| 欧美一级理论性理论a| 欧美aaa级| 午夜精品短视频| 欧美久久电影| 136国产福利精品导航网址| 欧美精品一区在线播放| 欧美久久久久久久| 国内精品久久久| 亚洲视频免费| 美女网站久久| 在线一区亚洲| 免费91麻豆精品国产自产在线观看| 欧美成人午夜激情视频| 国产一区二区三区电影在线观看| 红杏aⅴ成人免费视频| 销魂美女一区二区三区视频在线| 欧美阿v一级看视频| 欧美一级久久久| 欧美国产三级| 美女精品在线观看| 在线看欧美视频| 免费成人在线观看视频| 欧美一区二区视频在线观看| 国产精品嫩草99a| 亚洲欧美日韩天堂| 99re热这里只有精品视频| 欧美国产日韩一区二区在线观看| 亚洲欧洲一区二区天堂久久| 亚洲第一在线综合在线| 久久伊伊香蕉| 亚洲最新合集| 欧美一级欧美一级在线播放| 国产一区清纯| 欧美激情综合| 国产精品香蕉在线观看| 久久综合给合久久狠狠色| 欧美激情一区二区在线 | 欧美日韩四区| 欧美伊人久久久久久午夜久久久久 | 欧美日韩免费高清| 亚洲日本激情| 999亚洲国产精| 精品动漫一区| 这里只有精品电影| 亚洲电影第1页| 午夜精品一区二区三区在线视| 亚洲欧美视频在线观看视频| 国内成人精品一区| 亚洲图片在区色| 亚洲三级视频在线观看| 午夜精品久久久久| 在线性视频日韩欧美| 久久精品国产免费看久久精品| 国产精品亚洲不卡a| 久久免费精品视频| 欧美一区二区三区久久精品茉莉花 | 亚洲国产美国国产综合一区二区| 欧美jizz19hd性欧美| 欧美日韩视频专区在线播放| 欧美一区不卡| 欧美另类极品videosbest最新版本| 国产亚洲激情在线| 欧美在线1区| 欧美一区二区三区啪啪| 国产日韩在线不卡| 久久青草福利网站| 久久人人爽人人爽| 亚洲乱码国产乱码精品精| 亚洲国产日本| 欧美—级a级欧美特级ar全黄| av成人免费在线| av不卡在线看| 欧美系列一区| 欧美资源在线| 免费成人高清视频| 亚洲深夜福利视频| 欧美亚洲免费电影| 亚洲精品乱码久久久久久蜜桃麻豆 | 久久这里只精品最新地址| 在线播放日韩| 亚洲精品久久久久久久久久久久久 | 亚洲第一在线| 国产精品午夜在线观看| 久久综合图片| 欧美日韩伦理在线| 久久裸体艺术| 欧美日韩人人澡狠狠躁视频| 久久精品一本| 欧美日韩午夜视频在线观看| 久久精品中文字幕一区| 欧美激情1区2区3区| 欧美在线高清| 欧美日韩ab片| 欧美顶级大胆免费视频| 欧美手机在线| 亚洲国产日韩欧美一区二区三区| 国产伦精品一区二区三区免费迷 | 亚洲国产视频a| 国产欧美日韩专区发布| 亚洲人成亚洲人成在线观看| 国产一区二区三区最好精华液| 亚洲精品国产系列| 在线视频国产日韩| 亚洲国产日韩欧美在线99| 亚洲精品免费电影| 激情亚洲网站| 午夜久久久久久| 亚洲桃花岛网站| 欧美激情影院| 欧美激情一区二区| 精品成人一区二区| 性欧美1819性猛交| 亚洲欧美另类中文字幕| 欧美精品国产一区二区| 国产一区清纯| 美日韩精品视频| 国产欧美一区二区色老头| 亚洲久久一区二区| 91久久精品一区| 久久五月天婷婷| 久久综合九色综合欧美就去吻| 国产麻豆成人精品| 亚洲小说欧美另类婷婷| 亚洲小说欧美另类社区| 欧美日韩在线电影| 亚洲黄色大片| 日韩视频免费在线| 欧美精品电影在线| 亚洲人成在线播放| 一区二区三欧美| 欧美四级在线| 亚洲最新视频在线| 亚洲天堂成人在线观看| 欧美日韩免费一区二区三区| 亚洲精品一区二区三区婷婷月| 日韩一区二区精品在线观看| 欧美黄色大片网站| 最新日韩在线| 亚洲一区二区少妇| 国产嫩草一区二区三区在线观看| 亚洲欧美成人网| 久久久夜色精品亚洲| 在线观看91精品国产麻豆| 鲁大师影院一区二区三区| 亚洲高清资源综合久久精品| 亚洲日本理论电影| 欧美三级欧美一级| 校园激情久久| 亚洲成人在线网| 亚洲在线免费观看| 国内不卡一区二区三区| 欧美激情欧美激情在线五月| 中文精品一区二区三区| 久久久久se| 亚洲理论在线| 国内成人在线| 欧美体内谢she精2性欧美| 久久国产精品亚洲va麻豆| 亚洲黄一区二区| 欧美一区二区成人| 亚洲经典一区| 国产美女精品视频免费观看| 两个人的视频www国产精品| 日韩视频精品在线| 久久久精品久久久久| 日韩午夜一区| 国产精品天天看| 老牛国产精品一区的观看方式| 亚洲精品一区二区三区av| 久久精品一区二区三区不卡牛牛| 亚洲精品国精品久久99热| 国产欧美日韩精品专区| 欧美激情视频在线播放| 欧美在线啊v| 一区二区三区高清在线| 亚洲春色另类小说| 久久精品免费看| 亚洲无毛电影| 亚洲人成人一区二区三区| 国产一区二区高清| 欧美日韩亚洲一区在线观看| 久久久久国内| 欧美在线3区| 久久国产精品99精品国产| 亚洲视频你懂的| 亚洲美女视频在线观看| 老鸭窝毛片一区二区三区|