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

posts - 18,  comments - 5,  trackbacks - 0

一、題目描述

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


二、分析
      用DFS解決問題,詳細算法:割點與橋
三、代碼

 1#include<iostream>
 2#include<list>
 3using namespace std;
 4int n, r;
 5list<int> g[1001];
 6int num, lab[1001], low[1001];
 7list<pair<intint> > edge;
 8int degree[1001];
 9int parent[1001], rank[1001];
10void init_set()
11{
12    for(int i=1; i<1001; i++)
13    {
14        parent[i] = i;
15        rank[i] = 1;
16    }

17}

18int find(int k)
19{
20    if(parent[k] == k) 
21        return k;
22    else
23        return parent[k] = find(parent[k]);
24}

25void union_set(int u, int v)
26{
27    int pu = find(u), pv = find(v);
28    if(rank[pu] <= rank[pv])
29    {
30        parent[pu] = pv;
31        rank[pv] += pu;
32    }

33    else
34    {
35        parent[pv] = pu;
36        rank[pu] += pv;
37    }

38}

39void dfs(int u, int p)
40{
41    lab[u] = low[u] = num++;
42    list<int>::iterator it;
43    for(it = g[u].begin(); it != g[u].end(); it++)
44    {
45        int v = *it;
46        if(lab[v] == 0)
47        {
48            dfs(v, u);
49            low[u] = min(low[u], low[v]);
50            if(low[v] > lab[u])
51                edge.push_back(make_pair(u, v));
52            else
53                union_set(u, v); //u與v能進行縮點
54        }

55        else if(v != p)
56            low[u] = min(low[u], lab[v]);
57    }

58}

59int main()
60{
61    scanf("%d%d"&n, &r);
62    for(int i=1; i<=n; i++)
63        g[i].clear();
64    for(int i=1; i<=r; i++)
65    {
66        int v1, v2;
67        scanf("%d%d"&v1, &v2);
68        g[v1].push_back(v2);
69        g[v2].push_back(v1);
70    }

71    memset(lab, 0sizeof lab);
72    memset(low, 0x7fsizeof low);
73    num = 1;
74    init_set();
75    dfs(10);
76    memset(degree, 0sizeof degree);
77    list<pair<intint> >::iterator it;
78    int res = 0;
79    for(it = edge.begin(); it != edge.end(); it++)
80    {
81        int u = it->first, v = it->second;
82        degree[find(u)]++;
83        if(degree[find(u)] == 1)
84            res++;
85        else if(degree[find(u)] == 2)
86            res--;
87        degree[find(v)]++;
88        if(degree[find(v)] == 1)
89            res++;
90        else if(degree[find(v)] == 2)
91            res--;
92    }

93    printf("%d\n", (res+1/ 2);
94}
posted on 2009-07-05 16:08 Icyflame 閱讀(1435) 評論(0)  編輯 收藏 引用 所屬分類: 解題報告
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            一区二区亚洲精品国产| 欧美激情精品久久久| 国产在线精品一区二区夜色| 国产精品欧美日韩一区| 国产精品素人视频| 国产在线观看91精品一区| 好吊色欧美一区二区三区四区| 尤物视频一区二区| 中文国产成人精品| 久久成人在线| 欧美激情视频免费观看| 亚洲免费观看高清完整版在线观看熊 | 免费成人av在线| 免费久久久一本精品久久区| 欧美激情欧美狂野欧美精品 | 久久精品视频播放| 亚洲国产欧美日韩| 一区二区av| 久久久久久免费| 欧美视频四区| 在线不卡欧美| 午夜精品999| 亚洲高清免费在线| 欧美亚洲系列| 欧美性猛交一区二区三区精品| 韩国一区电影| 销魂美女一区二区三区视频在线| 欧美成人一品| 欧美一区国产在线| 国产精品高潮呻吟久久av无限| 亚洲第一毛片| 久久久999精品| 中文精品视频一区二区在线观看| 卡通动漫国产精品| 国产欧美在线视频| 亚洲午夜一区二区三区| 亚洲国产高清一区| 久久野战av| 狠狠色丁香久久婷婷综合_中| 亚洲影音一区| 一本久久青青| 欧美日韩视频在线一区二区观看视频| 樱花yy私人影院亚洲| 久久国产66| 亚洲综合视频在线| 欧美日韩中文字幕在线| 亚洲精品一区二区三区婷婷月| 久久久噜噜噜| 欧美一区二区三区的| 国产精品美女在线观看| 久久婷婷人人澡人人喊人人爽| 欧美日韩亚洲一区二区| 亚洲免费播放| 91久久国产精品91久久性色| 久久久亚洲综合| 极品裸体白嫩激情啪啪国产精品 | 日韩一级不卡| 欧美日韩国产综合视频在线| 欧美日韩一区二区三| 亚洲国产裸拍裸体视频在线观看乱了 | 极品少妇一区二区三区精品视频 | 亚洲国产成人av好男人在线观看| 亚欧成人精品| 亚洲欧美日韩精品| 欧美一区二区女人| 国产日韩欧美视频在线| 久久爱www久久做| 欧美亚洲视频一区二区| 国产亚洲欧美色| 久久久不卡网国产精品一区| 久久精品av麻豆的观看方式| 久久综合中文| 91久久久久久久久久久久久| 欧美激情一区二区三级高清视频| 免费欧美视频| 夜夜嗨av一区二区三区| 亚洲视频一区在线观看| 国产女主播一区二区| 老司机午夜精品| 欧美激情精品久久久久久黑人| aa成人免费视频| 亚洲一区中文| 伊人久久亚洲热| 亚洲电影视频在线| 国产精品国产三级国产aⅴ入口 | 亚洲视频欧美在线| 午夜精品一区二区三区在线播放| 激情视频一区| 日韩视频在线观看免费| 国产麻豆成人精品| 亚洲第一色在线| 国产精品入口麻豆原神| 欧美电影在线免费观看网站| 欧美性做爰毛片| 牛牛影视久久网| 国产精品欧美久久| 亚洲国产精品国自产拍av秋霞| 欧美性猛交一区二区三区精品| 久久久久久高潮国产精品视| 欧美久色视频| 久热精品在线视频| 欧美日韩天堂| 欧美福利在线| 国产原创一区二区| 中日韩美女免费视频网址在线观看| 国产一区二区三区在线播放免费观看| 最新日韩中文字幕| 伊人久久大香线蕉综合热线| 亚洲深夜影院| 一区二区三区视频在线 | 一区二区欧美亚洲| 亚洲国产精品久久久久秋霞不卡| 亚洲一区二区三区在线| 91久久精品美女| 亚洲午夜一二三区视频| 91久久精品视频| 欧美一区成人| 亚洲免费伊人电影在线观看av| 久久综合伊人| 久久久精品一区| 国产精品网站在线观看| 亚洲精品一区二区三区樱花| 亚洲国产视频a| 久久精品日产第一区二区| 欧美亚洲免费| 国产精品系列在线播放| 亚洲婷婷在线| 午夜久久福利| 国产精品日韩欧美| 中日韩视频在线观看| 国产精品99久久99久久久二8 | 午夜精品视频在线| 欧美三级特黄| 一区二区三区免费观看| 制服丝袜激情欧洲亚洲| 欧美日韩国产综合视频在线观看中文 | av不卡在线| 欧美激情欧美狂野欧美精品| 欧美成人精品一区| 亚洲人屁股眼子交8| 欧美激情综合亚洲一二区| 亚洲日本激情| 亚洲午夜精品国产| 国产精品久久久久久影院8一贰佰| av成人免费观看| 蜜桃久久av一区| 黄色成人在线观看| 乱人伦精品视频在线观看| 亚洲大片在线| 99视频在线精品国自产拍免费观看| 欧美精品在线观看91| 中文亚洲字幕| 久久久久免费| 亚洲人妖在线| 国产精品欧美激情| 久久蜜桃精品| 亚洲美女色禁图| 久久国产精品免费一区| 亚洲国产精品成人va在线观看| 欧美国产第二页| 亚洲综合国产精品| 欧美不卡视频一区| 亚洲一区二区三区色| 国内精品久久久久久久97牛牛| 欧美1区2区| 亚洲欧美另类国产| 亚洲第一色在线| 欧美在线播放视频| 亚洲欧洲日韩综合二区| 国产精品久久久久久影院8一贰佰 国产精品久久久久久影视 | 国产精品久久91| 亚洲国产欧美在线| 欧美日韩和欧美的一区二区| 亚洲一区在线直播| 欧美wwwwww| 午夜精品福利一区二区蜜股av| 在线观看一区| 国产精品无码永久免费888| 蜜桃精品久久久久久久免费影院| 一区二区日本视频| 欧美国产视频日韩| 久久精品在线观看| 亚洲视频观看| 亚洲国产精品精华液2区45| 国产精品亚洲视频| 欧美精品一卡| 老司机午夜精品| 欧美在线视频二区| 亚洲四色影视在线观看| 亚洲国产欧美在线| 久久一区二区视频| 欧美在线视频免费| 亚洲欧美激情四射在线日 | 亚洲成人资源| 国产精品视频免费观看www| 欧美日韩国产精品一卡| 欧美成年网站| 麻豆九一精品爱看视频在线观看免费| 午夜精品免费视频| 亚洲在线一区|