• <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>

            HDOJ 1856 More is better

            Problem Description
            Mr Wang wants some boys to help him with a project. Because the project is rather complex, the more boys come, the better it will be. Of course there are certain requirements.

            Mr Wang selected a room big enough to hold the boys. The boy who are not been chosen has to leave the room immediately. There are 10000000 boys in the room numbered from 1 to 10000000 at the very beginning. After Mr Wang's selection any two of them who are still in this room should be friends (direct or indirect), or there is only one boy left. Given all the direct friend-pairs, you should decide the best way.
             


             

            Input
            The first line of the input contains an integer n (0 ≤ n ≤ 100 000) - the number of direct friend-pairs. The following n lines each contains a pair of numbers A and B separated by a single space that suggests A and B are direct friends. (A ≠ B, 1 ≤ A, B ≤ 10000000)
             


             

            Output
            The output in one line contains exactly one integer equals to the maximum number of boys Mr Wang may keep.
             


             

            Sample Input
            4
            1 2
            3 4
            5 6
            1 6
            4
            1 2
            3 4
            5 6
            7 8
             


             

            Sample Output
            4
            2
            
            Hint
            A and B are friends(direct or indirect), B and C are friends(direct or indirect), then A and C are also friends(indirect). In the first sample {1,2,5,6} is the result. In the second sample {1,2},{3,4},{5,6},{7,8} are four kinds of answers.
                這題的意思很簡單,要求最多有多少個點是連通的,可用并查集或者搜索。我的做法是dfs+鄰接表,第一次用vector模擬了下鄰接表,感覺效果還可以,要是STL的效率能再高點,就完美了。(但是這是不可能的)
             1 #include <iostream>
             2 #include <vector>
             3 using namespace std;
             4 
             5 vector< vector<int> > map;
             6 int n,ans,cnt;
             7 bool visited[100001];
             8 
             9 void dfs(int u){
            10     visited[u]=true;
            11     for(int i=0;i<map[u].size();i++)
            12         if(!visited[map[u][i]])
            13             cnt++,dfs(map[u][i]);
            14 }
            15 int main(){
            16     int u,v,i,m;
            17     while(scanf("%d",&n)!=EOF){
            18         map.clear();
            19         map.resize(100001);
            20         memset(visited,false,sizeof(visited));
            21         for(m=i=0;i<n;i++){
            22             scanf("%d %d",&u,&v);
            23             m=m>? m:u;
            24             m=m>? m:v;
            25             map[u].push_back(v),map[v].push_back(u);
            26         }
            27         for(ans=i=1;i<=m;i++){
            28             if(!visited[i])
            29                 cnt=1,dfs(i);
            30             ans=ans>cnt ? ans:cnt;
            31         }
            32         printf("%d\n",ans);
            33     }
            34     return 0;
            35 }

            posted on 2009-04-27 16:34 極限定律 閱讀(465) 評論(0)  編輯 收藏 引用 所屬分類: ACM/ICPC

            <2009年4月>
            2930311234
            567891011
            12131415161718
            19202122232425
            262728293012
            3456789

            導航

            統計

            常用鏈接

            留言簿(10)

            隨筆分類

            隨筆檔案

            友情鏈接

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            国产精品美女久久久久网| 久久亚洲日韩看片无码| 亚洲欧美成人综合久久久| 久久久噜噜噜久久中文字幕色伊伊| 精品熟女少妇av免费久久| 欧美午夜精品久久久久免费视| 一本久道久久综合狠狠躁AV| 亚洲国产日韩欧美久久| 日韩亚洲国产综合久久久| 日韩久久久久中文字幕人妻| 久久青青草原精品国产不卡| 亚洲另类欧美综合久久图片区| 亚洲日本久久久午夜精品| 亚洲狠狠婷婷综合久久久久| 无码精品久久久天天影视| 丁香五月网久久综合| 精品国产91久久久久久久a| 久久天天躁狠狠躁夜夜av浪潮| 婷婷久久综合九色综合绿巨人| 久久久久久久精品成人热色戒| 亚洲伊人久久精品影院| 国产亚洲美女精品久久久久狼| 国产精品亚洲综合专区片高清久久久 | 久久综合久久美利坚合众国| 国内精品久久久久国产盗摄| 久久只这里是精品66| 久久综合88熟人妻| 欧美喷潮久久久XXXXx| 国产ww久久久久久久久久| 久久有码中文字幕| 国产精品禁18久久久夂久| 久久伊人亚洲AV无码网站| 久久久久久久久久久久中文字幕 | 一极黄色视频久久网站| 国产午夜免费高清久久影院 | 亚洲欧美一区二区三区久久| 久久精品亚洲中文字幕无码麻豆 | 五月丁香综合激情六月久久| 91精品国产91热久久久久福利 | 性欧美丰满熟妇XXXX性久久久 | 国产一久久香蕉国产线看观看|