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

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://m.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[]搞的,刪除重邊。  回復  更多評論   

<2012年7月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

導航

統計

常用鏈接

留言簿(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>
            国产一区二区毛片| 亚洲毛片网站| 欧美一区免费视频| 欧美韩日一区二区| 乱码第一页成人| 一区视频在线看| 久久全国免费视频| 欧美一区日韩一区| 国产区在线观看成人精品| 亚洲一二区在线| 亚洲永久精品大片| 蜜臀va亚洲va欧美va天堂| 亚洲午夜高清视频| 亚洲女同同性videoxma| 欧美人与性动交a欧美精品| 蜜桃伊人久久| 黄色工厂这里只有精品| 亚洲一区二区精品| 午夜免费久久久久| 国产精品久久久久免费a∨大胸 | 亚洲在线观看免费视频| 欧美激情一区二区| 欧美国产综合视频| 伊人久久亚洲影院| 久久亚洲精品中文字幕冲田杏梨| 欧美中在线观看| 依依成人综合视频| 欧美三级电影网| 宅男精品视频| 久久性天堂网| 亚洲免费久久| 国产日韩欧美一二三区| 久久躁日日躁aaaaxxxx| 欧美国产日韩免费| 亚洲一本大道在线| 国内成人自拍视频| 欧美高潮视频| 午夜视频在线观看一区二区三区 | 国产日韩精品一区二区浪潮av| 美女黄网久久| 久久香蕉国产线看观看av| 久久成人国产精品| 麻豆9191精品国产| 欧美成人伊人久久综合网| 久久久噜噜噜久久中文字免| 久久婷婷丁香| 日韩一级二级三级| 中文国产成人精品久久一| 一区二区三区四区精品| 亚洲一区二区在线看| 久久www成人_看片免费不卡| 久久影视三级福利片| 男女av一区三区二区色多| 欧美日韩免费在线观看| 国产精品露脸自拍| 亚洲黄色性网站| 国产精品99久久99久久久二8 | 欧美日韩亚洲综合在线| 欧美日韩国产高清| 国产色产综合色产在线视频| 亚洲高清在线播放| 亚洲女ⅴideoshd黑人| 免费在线一区二区| 亚洲视频在线观看| 欧美精品一卡| 在线观看日韩专区| 欧美中在线观看| 一二三区精品| 欧美日韩1区2区3区| 黄色精品网站| 久久激情网站| 亚洲无线一线二线三线区别av| 鲁大师影院一区二区三区| 国产午夜精品视频| 欧美亚洲一区| 亚洲一区二区三区在线观看视频 | 亚洲乱码国产乱码精品精天堂| 欧美亚洲免费| 中文亚洲欧美| 国产欧美日韩综合一区在线播放| 一区二区三区www| 一本色道久久综合| 一区二区激情视频| 午夜久久久久久| 久久精品道一区二区三区| 开心色5月久久精品| 欧美成人一二三| 中文无字幕一区二区三区| 欧美影院在线| 欧美精品福利| 国产欧美日韩三级| 99精品福利视频| 亚洲欧美日韩精品久久亚洲区| 亚洲午夜久久久久久久久电影院| 欧美一级视频| 久久婷婷麻豆| 亚洲欧美激情诱惑| 美女啪啪无遮挡免费久久网站| 欧美精品一级| 一本色道久久加勒比88综合| 国产精品99久久久久久久女警 | 国产伦精品一区二区三区照片91| 亚洲精品国产精品久久清纯直播| 欧美1区视频| 亚洲综合色噜噜狠狠| 亚洲永久免费| 欧美韩日一区| 亚洲国产日韩在线| 一区二区三欧美| 亚洲第一二三四五区| 亚洲欧美国产不卡| 欧美黄色精品| 在线不卡中文字幕| 久久久福利视频| 欧美一区二区视频在线观看2020 | 久久久久久精| 国产一区二区精品久久99| 亚洲欧美日韩国产中文在线| 亚洲啪啪91| 久久高清免费观看| 免费高清在线视频一区·| 有坂深雪在线一区| 在线午夜精品自拍| 亚洲第一区在线观看| 妖精成人www高清在线观看| 国产精品久久久久999| 久久激情综合网| 欧美国产日韩xxxxx| 亚洲欧美一区二区激情| 久久久久久亚洲综合影院红桃 | 欧美国产日本| 久久精品成人一区二区三区蜜臀| 久久漫画官网| 香蕉久久夜色精品| 欧美黑人多人双交| 欧美伊人久久久久久久久影院 | 亚洲深夜激情| 久久婷婷麻豆| 裸体一区二区三区| 国产精品亚洲产品| 欧美一区二区三区免费观看| 久久xxxx| 很黄很黄激情成人| 亚洲人成在线观看网站高清| 日韩视频在线一区| 国产日韩精品视频一区二区三区| 亚洲男人的天堂在线aⅴ视频| 亚洲欧美资源在线| 亚洲少妇最新在线视频| 欧美日韩综合网| 老司机一区二区| 久久久人成影片一区二区三区观看 | 日韩视频一区二区在线观看 | 久久精品视频在线观看| 美女露胸一区二区三区| 午夜激情亚洲| 欧美金8天国| 久久久久久久综合| 国产精品久久| 亚洲大胆视频| 国产精品国产三级欧美二区| 欧美88av| 国产九区一区在线| 亚洲经典自拍| 99国产精品自拍| 亚洲欧美综合精品久久成人| 亚洲精品一区二区三| 欧美黄色一区| 欧美国产日韩免费| 国产一区二区主播在线| 午夜精品久久久久影视| 媚黑女一区二区| 日韩一区二区精品视频| 99精品欧美| 亚洲国产精品免费| 国产区精品在线观看| 91久久在线观看| 亚洲乱码一区二区| 一区二区三区在线不卡| 黄色在线一区| 国产精品久久久久天堂| 久久婷婷国产综合国色天香| 亚洲男同1069视频| 久久精品最新地址| 久久久国产视频91| 久久精品中文字幕一区| 在线免费日韩片| 国产精品色婷婷| 亚洲一区二区视频在线| 欧美专区在线| 欧美在线亚洲| 亚洲宅男天堂在线观看无病毒| 一本色道久久加勒比精品 | 欧美在线日韩| 黄色日韩精品| 欧美成人一区二区三区在线观看 | 亚洲人成人99网站| 午夜精品一区二区三区在线播放| 免费欧美电影| 亚洲精品美女在线|