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

POJ 3177 Redundant Paths 雙連通分量+縮點

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


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

#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 極限定律 閱讀(1564) 評論(4)  編輯 收藏 引用 所屬分類: ACM/ICPC

評論

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

省去hash可以這樣判重空間小很多 時間沒多多少 依然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;
}  回復  更多評論   

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

我也想這樣做的,不過怕時間效率變低,就偷懶直接HASH了@zeus
  回復  更多評論   

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

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

# re: POJ 3177 Redundant Paths 雙連通分量+縮點[未登錄] 2012-07-31 20:48 bigrabbit

樓主,我發現個問題。這組數據對于下面的數據
5 6
1 2
1 3
2 3
3 4
3 5
4 5
輸出的low數組是 0 0 0 1 1
是不對的,應該是0 0 0 0 0,你建圖的方式很奇怪,我也看不懂你到底是怎么建圖的。可以解釋下嗎?我直接用vector<int> edg[]搞的,刪除重邊。  回復  更多評論   

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

導航

統計

常用鏈接

留言簿(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>
            宅男精品导航| 亚洲国产精品悠悠久久琪琪| 中文精品视频| 在线视频你懂得一区| 欧美日韩成人一区| 午夜精品免费在线| 性欧美暴力猛交69hd| 国内精品写真在线观看| 久久久欧美精品sm网站| 美日韩精品免费观看视频| 亚洲高清资源综合久久精品| 亚洲大胆av| 欧美激情成人在线| 亚洲永久网站| 久久久91精品国产| av成人免费在线观看| 亚洲无线视频| 亚洲二区在线视频| 一区二区三区欧美视频| 国产欧美一区二区三区在线老狼 | 美女视频黄免费的久久| 一区二区三区四区国产精品| 亚洲一区综合| 亚洲精品久久7777| 亚洲欧美视频在线观看视频| 亚洲国产成人在线| 亚洲一区二区三区四区五区黄| 激情综合激情| 中国成人在线视频| 亚洲大胆美女视频| 亚洲欧美日韩国产另类专区| 亚洲国产一区二区在线| 亚洲一区999| 最近看过的日韩成人| 亚洲女同同性videoxma| 亚洲毛片一区| 久久精品国产96久久久香蕉| 在线视频精品一区| 免费av成人在线| 欧美主播一区二区三区| 欧美日韩在线不卡一区| 欧美成人精品影院| 国产视频欧美| 亚洲校园激情| 亚洲一区激情| 欧美巨乳在线观看| 欧美韩国在线| 黄色成人av网站| 欧美在线影院在线视频| 亚洲欧美另类在线观看| 欧美激情综合网| 亚洲第一网站| 亚洲国产精品激情在线观看| 亚洲欧美一区二区三区极速播放| 中日韩美女免费视频网站在线观看| 久久综合精品一区| 久久久亚洲精品一区二区三区| 国产精品久久久久久久久借妻| 最新国产の精品合集bt伙计| 亚洲激情啪啪| 欧美成人精品h版在线观看| 六月天综合网| 亚洲电影毛片| 欧美成人精品在线| 亚洲韩国一区二区三区| 亚洲人成人一区二区三区| 狂野欧美激情性xxxx| 美女精品国产| 亚洲高清在线视频| 欧美裸体一区二区三区| 亚洲精品国产拍免费91在线| 一区二区欧美在线观看| 欧美三级小说| 亚洲视频专区在线| 久久爱www.| 狠狠干成人综合网| 老司机午夜精品| 亚洲国产mv| 亚洲先锋成人| 国产视频在线观看一区| 久久久欧美精品sm网站| 亚洲成色www8888| 亚洲性感激情| 国内精品伊人久久久久av影院| 久久久久久久网站| 亚洲日本中文字幕| 午夜久久tv| 亚洲国产经典视频| 欧美色精品天天在线观看视频| 亚洲私人影院| 欧美99在线视频观看| 日韩午夜三级在线| 国产麻豆精品theporn| 久久精品一区二区三区中文字幕| 亚洲第一福利在线观看| 亚洲深夜福利在线| 国内精品美女av在线播放| 欧美高清在线视频| 性欧美大战久久久久久久久| 欧美激情一区二区三区在线视频观看 | 1024日韩| 国产精品v日韩精品v欧美精品网站| 亚洲欧美在线一区二区| 欧美激情视频免费观看| 性色av香蕉一区二区| 最近中文字幕日韩精品 | 亚洲精品亚洲人成人网| 国产精品一区一区三区| 欧美大片在线看| 亚洲综合欧美日韩| 亚洲国产成人不卡| 久久久久久久网站| 亚洲一区在线看| 亚洲激情网址| 国产又爽又黄的激情精品视频| 欧美精品videossex性护士| 欧美一区午夜精品| 这里只有视频精品| 亚洲人午夜精品| 欧美 日韩 国产在线| 欧美伊人久久久久久午夜久久久久 | 91久久精品国产91久久| 国产精品夜色7777狼人| 欧美精品尤物在线| 美女诱惑一区| 久久久久国产免费免费| 亚洲欧美日韩精品久久久| 日韩天堂在线观看| 亚洲精品乱码久久久久| 欧美不卡高清| 麻豆久久精品| 欧美不卡福利| 欧美国产高清| 欧美激情成人在线视频| 狂野欧美激情性xxxx欧美| 久久激情综合| 玖玖综合伊人| 麻豆91精品| 美日韩精品视频免费看| 麻豆国产精品777777在线| 久久色在线播放| 久久综合99re88久久爱| 久久一区二区精品| 蘑菇福利视频一区播放| 欧美www视频在线观看| 女仆av观看一区| 亚洲福利在线观看| 最新日韩在线视频| 91久久在线| 亚洲无限乱码一二三四麻| 亚洲免费中文字幕| 欧美在线999| 久久久亚洲综合| 欧美国产精品一区| 欧美日韩精品久久久| 国产精品国产亚洲精品看不卡15| 国产精品成人在线观看| 国产精品视频在线观看| 国产亚洲欧洲一区高清在线观看 | 欧美www视频在线观看| 欧美黄色免费网站| 欧美午夜一区二区三区免费大片 | 国产精品亚洲综合| 国产在线拍偷自揄拍精品| 亚洲成人原创| 一区二区欧美在线| 久久久久久久综合日本| 另类图片国产| 99re6热在线精品视频播放速度| 亚洲无线一线二线三线区别av| 香蕉国产精品偷在线观看不卡 | 亚洲精品一区在线观看香蕉| 亚洲一区中文| 美国十次成人| 国产精品国产精品国产专区不蜜| 国产欧美日韩在线播放| 91久久久精品| 久久av红桃一区二区小说| 欧美不卡视频| 亚洲免费在线| 欧美成人自拍视频| 国产日韩在线一区| 亚洲精品国产欧美| 久久精品亚洲一区| 亚洲欧洲精品一区二区| 香蕉久久夜色精品国产| 欧美国产高潮xxxx1819| 国产日韩视频| 亚洲一区不卡| 亚洲大胆视频| 欧美在线黄色| 欧美视频一区| 亚洲卡通欧美制服中文| 久久精品在线免费观看| 妖精成人www高清在线观看| 久久久免费精品| 国外精品视频| 午夜在线视频观看日韩17c| 亚洲人成在线观看| 久久综合图片|