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

POJ 3177 Redundant Paths 雙連通分量+縮點(diǎn)

Description

In order to get from one of the F (1 <= F <= 5,000) grazing fields (which are numbered 1..F) to another field, Bessie and the rest of the herd are forced to cross near the Tree of Rotten Apples. The cows are now tired of often being forced to take a particular path and want to build some new paths so that they will always have a choice of at least two separate routes between any pair of fields. They currently have at least one route between each pair of fields and want to have at least two. Of course, they can only travel on Official Paths when they move from one field to another.

Given a description of the current set of R (F-1 <= R <= 10,000) paths that each connect exactly two different fields, determine the minimum number of new paths (each of which connects exactly two fields) that must be built so that there are at least two separate routes between any pair of fields. Routes are considered separate if they use none of the same paths, even if they visit the same intermediate field along the way.

There might already be more than one paths between the same pair of fields, and you may also build a new path that connects the same fields as some other path.

Input

Line 1: Two space-separated integers: F and R

Lines 2..R+1: Each line contains two space-separated integers which are the fields at the endpoints of some path.

Output

Line 1: A single integer that is the number of new paths that must be built.

Sample Input

7 7
1 2
2 3
3 4
2 5
4 5
5 6
5 7

Sample Output

2

Hint

Explanation of the sample:

One visualization of the paths is:
   1   2   3
+---+---+
| |
| |
6 +---+---+ 4
/ 5
/
/
7 +
Building new paths from 1 to 6 and from 4 to 7 satisfies the conditions.
   1   2   3
+---+---+
: | |
: | |
6 +---+---+ 4
/ 5 :
/ :
/ :
7 + - - - -
Check some of the routes:
1 – 2: 1 –> 2 and 1 –> 6 –> 5 –> 2
1 – 4: 1 –> 2 –> 3 –> 4 and 1 –> 6 –> 5 –> 4
3 – 7: 3 –> 4 –> 7 and 3 –> 2 –> 5 –> 7

Every pair of fields is, in fact, connected by two routes.

It's possible that adding some other path will also solve the problem (like one from 6 to 7). Adding two paths, however, is the minimum.

Source


    題意大意:一群牛將被在一個(gè)特定路徑構(gòu)成的農(nóng)場(chǎng)上遷移,每?jī)蓧K農(nóng)場(chǎng)之間都至少有一條通道,這些牛要求每?jī)蓧K路徑至少要有兩條通道,求最少需要修建多少條路才能滿足要求。
    這題的解法與http://www.shnenglu.com/mythit/archive/2009/05/29/86082.html完全一樣,只是題目中說(shuō)了圖中有可能存在平行邊,這里必須判斷一下。我還是很偷懶的用了STL里的vector模擬鄰接矩陣,并且開(kāi)了個(gè)5001*5001的bool數(shù)組判斷平行邊。結(jié)果導(dǎo)致代碼的效率和空間消耗都很大,110MS和將近24M的內(nèi)存空間。如果自己建圖的話,效率能提高很多。

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

const int MAXN = 5001;
vector
< vector<int> > adj;
bool hash[MAXN][MAXN];
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;
    
while(scanf("%d %d",&n,&m)!=EOF){
        adj.assign(n
+1,vector<int>());
        memset(hash,
false,sizeof(hash));
        
while(m--){
            scanf(
"%d %d",&u,&v);
            
if(!hash[u][v]){
                hash[u][v]
=true;
                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-30 01:18 極限定律 閱讀(1575) 評(píng)論(4)  編輯 收藏 引用 所屬分類: ACM/ICPC

評(píng)論

# re: POJ 3177 Redundant Paths 雙連通分量+縮點(diǎn) 2009-08-14 09:53 zeus

省去hash可以這樣判重空間小很多 時(shí)間沒(méi)多多少 依然0ms
bool isok( int u, int v )//判重
{
for ( int i= 0; i< g[u].size(); ++i )
if ( g[u][i]== v ) return false;

return true;
}  回復(fù)  更多評(píng)論   

# re: POJ 3177 Redundant Paths 雙連通分量+縮點(diǎn) 2009-08-14 20:55 極限定律

我也想這樣做的,不過(guò)怕時(shí)間效率變低,就偷懶直接HASH了@zeus
  回復(fù)  更多評(píng)論   

# re: POJ 3177 Redundant Paths 雙連通分量+縮點(diǎn) 2011-04-28 09:30 Icyeye

拜讀了哈,幫助很大,謝啦^-^
但是有一點(diǎn),那個(gè)visit[u]=2不知道有什么用,但注釋掉后能快三分之二左右的時(shí)間~~  回復(fù)  更多評(píng)論   

# re: POJ 3177 Redundant Paths 雙連通分量+縮點(diǎn)[未登錄](méi) 2012-07-31 20:48 bigrabbit

樓主,我發(fā)現(xiàn)個(gè)問(wèn)題。這組數(shù)據(jù)對(duì)于下面的數(shù)據(jù)
5 6
1 2
1 3
2 3
3 4
3 5
4 5
輸出的low數(shù)組是 0 0 0 1 1
是不對(duì)的,應(yīng)該是0 0 0 0 0,你建圖的方式很奇怪,我也看不懂你到底是怎么建圖的??梢越忉屜聠??我直接用vector<int> edg[]搞的,刪除重邊。  回復(fù)  更多評(píng)論   

<2009年6月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

導(dǎo)航

統(tǒng)計(jì)

常用鏈接

留言簿(10)

隨筆分類

隨筆檔案

友情鏈接

搜索

最新評(píng)論

閱讀排行榜

評(píng)論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            国产亚洲欧美激情| 久久久蜜桃精品| 午夜精品影院在线观看| 久久国产精品99国产精| 有码中文亚洲精品| 亚洲高清视频在线观看| 老**午夜毛片一区二区三区| 亚洲欧洲一级| 一本久道久久综合婷婷鲸鱼| 国产精品久久久久影院亚瑟| 久久99伊人| 久久资源av| 日韩一级欧洲| 亚洲伊人久久综合| 在线精品福利| 日韩亚洲在线| 国产一区二区主播在线| 欧美激情自拍| 国产精品福利网站| 久久综合五月| 欧美日韩美女| 欧美性色aⅴ视频一区日韩精品| 国产精品久久久久久av下载红粉| 久久精品二区三区| 欧美xx69| 欧美一区视频在线| 欧美www视频| 欧美在线播放视频| 欧美777四色影视在线| 亚洲女人小视频在线观看| 久久国产精品一区二区| 一区电影在线观看| 欧美专区日韩视频| 一区二区三区久久| 久久久99精品免费观看不卡| 一区二区高清| 久久久久国色av免费看影院| 亚洲午夜激情在线| 久久免费视频在线| 午夜精品国产更新| 欧美福利一区二区| 欧美一级专区| 欧美精品91| 久久综合久久久久88| 欧美色图一区二区三区| 蜜桃av一区二区三区| 欧美日韩中文字幕精品| 免费在线观看一区二区| 国产精品久久久久久久电影 | 中文久久乱码一区二区| 永久555www成人免费| 亚洲午夜高清视频| 亚洲人成网在线播放| 性做久久久久久免费观看欧美 | 久久亚洲精品中文字幕冲田杏梨| 亚洲视频在线一区观看| 久久综合五月| 久久精品国产一区二区三| 欧美日韩国产不卡| 欧美大胆人体视频| 国产亚洲人成a一在线v站 | 亚洲人成在线播放| 欧美在线观看视频在线| 亚洲在线一区二区| 欧美劲爆第一页| 免费91麻豆精品国产自产在线观看| 国产精品户外野外| 亚洲国产一区在线| 一区二区视频欧美| 亚洲欧美精品| 噜噜爱69成人精品| 亚洲精品美女久久7777777| 欧美在线视频二区| 午夜在线成人av| 欧美日韩日本国产亚洲在线| 欧美激情女人20p| 影音先锋中文字幕一区二区| 西西人体一区二区| 午夜在线观看免费一区| 欧美性做爰毛片| 日韩视频不卡| 日韩一区二区精品视频| 欧美1区2区| 欧美成人精品h版在线观看| 黑丝一区二区三区| 亚洲欧美清纯在线制服| 亚洲欧美在线aaa| 欧美极品色图| 亚洲人成7777| 亚洲每日在线| 欧美国产精品va在线观看| 欧美激情按摩| 91久久亚洲| 麻豆成人综合网| 免费在线成人| 91久久久久| 欧美11—12娇小xxxx| 欧美激情亚洲视频| 亚洲三级性片| 欧美精品入口| 亚洲每日更新| 亚洲午夜性刺激影院| 欧美日韩一区三区四区| 一区二区不卡在线视频 午夜欧美不卡在 | 亚洲激情综合| 日韩特黄影片| 欧美日韩国产不卡| 99精品欧美一区二区三区综合在线| 99国产精品99久久久久久粉嫩| 欧美高清视频一区| 91久久久久久久久| 一区二区三区精品视频| 欧美色偷偷大香| 亚洲人成在线观看一区二区| 日韩午夜精品| 国产精品s色| 午夜欧美精品久久久久久久| 久久精品视频免费| 有坂深雪在线一区| 欧美激情va永久在线播放| 欧美在线综合| 国产综合av| 久久综合色88| 在线免费观看日本一区| 亚洲综合丁香| 久久久青草婷婷精品综合日韩| 精久久久久久| 欧美岛国在线观看| 一区二区久久久久| 久久精品国产免费观看| 一区二区三区自拍| 欧美女主播在线| 亚洲一区二区精品视频| 久久久久国产精品一区| 亚洲高清一区二区三区| 亚洲在线一区| 麻豆国产va免费精品高清在线| 亚洲激情小视频| 欧美网站在线观看| 欧美影院久久久| 亚洲国产成人精品久久| 亚洲一区二区三区四区视频| 国产亚洲精品高潮| 欧美暴力喷水在线| 中文在线资源观看视频网站免费不卡| 性亚洲最疯狂xxxx高清| 在线免费不卡视频| 欧美性大战久久久久久久| 欧美在线视频免费播放| 亚洲一区二区三区午夜| 国产一区二区三区日韩| 欧美国产高清| 亚洲欧美日韩国产综合| 欧美激情视频给我| 亚洲欧美日本国产有色| 在线播放国产一区中文字幕剧情欧美| 欧美乱大交xxxxx| 欧美亚洲专区| 亚洲国语精品自产拍在线观看| 午夜久久影院| 亚洲激情自拍| 国产欧美短视频| 欧美韩日精品| 欧美一区二区视频在线| 亚洲人成网站影音先锋播放| 亚洲高清久久| 国产精品一区二区在线| 免费成年人欧美视频| 亚洲在线免费视频| 亚洲国产视频直播| 久久精品一区二区三区不卡| 99国产精品久久久久老师| 国产日产高清欧美一区二区三区| 欧美成人激情在线| 欧美一级理论性理论a| 日韩视频久久| 欧美成人精精品一区二区频| 先锋影音久久久| 亚洲精品偷拍| 国语自产精品视频在线看一大j8 | 91久久久国产精品| 国产日韩在线一区二区三区| 欧美久久久久中文字幕| 久久久精品一品道一区| 亚洲香蕉视频| 亚洲日本激情| 麻豆精品网站| 欧美视频网址| 亚洲欧美精品伊人久久| 91久久国产自产拍夜夜嗨| 久久伊人精品天天| 香蕉成人啪国产精品视频综合网| 亚洲精品社区| 18成人免费观看视频| 国产欧美日韩综合精品二区| 欧美日韩视频第一区| 蜜臀av一级做a爰片久久 | 久久久中精品2020中文| 亚洲一区在线观看视频| 99re6这里只有精品|