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

            hrbeuTLt4

            The Accomodation of Students

            TimeLimit: 1 Second   MemoryLimit: 32 Megabyte

            Totalsubmit: 26   Accepted: 9  

            Description

            There are a group of students. Some of them may know each other, while others don't. For example, A and B know each other, B and C know each other. But this may not imply that A and C know each other.

            Now you are given all pairs of students who know each other. Your task is to divide the students into two groups so that any two students in the same group don't know each other.If this goal can be achieved, then arrange them into double rooms. Remember, only paris appearing in the previous given set can live in the same room, which means only known students can live in the same room.

            Calculate the maximum number of pairs that can be arranged into these double rooms.

            Input

            For each data set:
            The first line gives two integers, n and m(1<n<=200), indicating there are n students and m pairs of students who know each other. The next m lines give such pairs.

            Proceed to the end of file.

            Output

            If these students cannot be divided into two groups, print "No". Otherwise, print the maximum number of pairs that can be arranged in those rooms.

            Sample Input

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

            Sample Output

            No
            3

            Source

            2008 Asia Harbin Regional Contest Online

            最近一直沒寫blog

            發(fā)現(xiàn)二分圖還是不太會(huì)做
            這個(gè)題是先判斷是不是二分圖,然后求最大匹配
            題意

            有n個(gè)學(xué)生,有m對(duì)人是認(rèn)識(shí)的,每一對(duì)認(rèn)識(shí)的人能分到一間房,問能否把n個(gè)學(xué)生分成兩

            部分,每部分內(nèi)的學(xué)生互不認(rèn)識(shí),而兩部分之間的學(xué)生認(rèn)識(shí)。如果可以分成兩部分,就

            算出房間最多需要多少間,否則就輸出No。

            #include<stdio.h>
            #include
            <string.h>
            #include
            <math.h>
            #define maxn 205
            int n,m;
            int g[maxn][maxn];
            int color[maxn];
            int cx[maxn],cy[maxn];
            int mk[maxn];
            int ans;
            bool flag;
            int path(int u)
            {
                
            int v;
                
            for(v=1; v<=n; v++)
                
            {
                    
            if(g[u][v]&&!mk[v])
                    
            {
                        mk[v]
            =1;
                        
            if(cy[v]==-1||path(cy[v]))
                        
            {
                            cx[u]
            =v;
                            cy[v]
            =u;
                            
            return 1;
                        }

                    }

                }

                
            return 0;
            }

            int match()
            {
                
            int res,i;
                res
            =0;
                memset(cx,
            -1,sizeof(cx));
                memset(cy,
            -1,sizeof(cy));
                
            for(i=1; i<=n; i++)
                    
            if(cx[i]==-1)
                    
            {
                        memset(mk,
            0,sizeof(mk));
                        res
            +=path(i);
                    }

                
            return res;
            }

            void dfs(int u,int col)
            {
                
            int i;
                color[u]
            =col;
                
            for(i=1;i<n;i++)
                    
            if((g[u][i]||g[i][u])&&color[i]==-1&&flag)
                
            {
                    dfs(i,
            1-col);
                }

                
            else if((g[u][i]||g[i][u])&&color[i]==col)
                
            {
                    flag
            =false;
                    
            return;
                }

            }

            int main()
            {
                
            int i,j;
                
            int p1,p2;
                
            while(scanf("%d%d",&n,&m)!=EOF)
                
            {
                    memset(g,
            0,sizeof(g));
                    
            for(i=1; i<=m; i++)
                    
            {
                        scanf(
            "%d%d",&p1,&p2);
                        g[p1][p2]
            =1;
                    }

                    ans
            =0;
                    flag
            =true;
                    memset(color,
            -1,sizeof(color));
                    dfs(
            1,0);
                    
            if (!flag) printf("No\n");
                    
            else 
                    
            {
                        ans
            =match();
                        printf(
            "%d\n",ans);
                    }

                }

                
            return 0;
            }


            //二分圖判斷+最大匹配



             

            posted on 2012-04-24 15:18 jh818012 閱讀(92) 評(píng)論(0)  編輯 收藏 引用


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評(píng)論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當(dāng)于是 取余3的意思 因?yàn)?3 的 二進(jìn)制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄]
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評(píng)論內(nèi)容較長(zhǎng),點(diǎn)擊標(biāo)題查看
            • --王私江
            久久久精品一区二区三区| 久久久久女教师免费一区| …久久精品99久久香蕉国产| 2021久久国自产拍精品| 无码人妻少妇久久中文字幕| 久久ZYZ资源站无码中文动漫| 国产成人精品久久亚洲高清不卡| 中文字幕精品久久久久人妻| 99久久99久久精品国产| 亚洲va久久久噜噜噜久久天堂| 日本久久久久久中文字幕| 久久久久人妻一区二区三区| 久久精品国产亚洲av麻豆小说 | 久久ww精品w免费人成| 久久精品成人免费国产片小草| 久久精品国产亚洲AV无码麻豆| 亚洲国产一成久久精品国产成人综合 | 久久国产精品波多野结衣AV| 浪潮AV色综合久久天堂| 亚洲精品无码久久久| 欧美综合天天夜夜久久| 99999久久久久久亚洲| 午夜不卡久久精品无码免费| 亚洲第一永久AV网站久久精品男人的天堂AV| 久久亚洲AV成人无码电影| 精品伊人久久大线蕉色首页| 亚洲精品无码久久毛片| 久久人人爽人爽人人爽av| 国产亚洲成人久久| 狠狠色伊人久久精品综合网| 国产成人精品久久一区二区三区av| 99久久免费国产精品热| 久久国产精品99精品国产987| 久久超乳爆乳中文字幕| 99久久精品国产免看国产一区| 久久精品国产亚洲AV高清热| 久久精品国产亚洲AV嫖农村妇女| 日产精品久久久一区二区| 久久久精品国产sm调教网站| 久久国产精品99精品国产987| 99久久人人爽亚洲精品美女|