• <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>
            posts - 7,comments - 3,trackbacks - 0

            1099. Work Scheduling

            Time Limit: 0.5 second
            Memory Limit: 16 MB
            There is certain amount of night guards that are available to protect the local junkyard from possible junk robberies. These guards need to scheduled in pairs, so that each pair guards at different night. The junkyard CEO ordered you to write a program which given the guards characteristics determines the maximum amount of scheduled guards (the rest will be fired). Please note that each guard can be scheduled with only one of his colleagues and no guard can work alone.

            Input

            The first line of the input contains one number N ≤ 222 which is the amount of night guards. Unlimited number of lines consisting of unordered pairs (ij) follow, each such pair means that guard #i and guard #j can work together, because it is possible to find uniforms that suit both of them (The junkyard uses different parts of uniforms for different guards i.e. helmets, pants, jackets. It is impossible to put small helmet on a guard with a big head or big shoes on guard with small feet). The input ends with Eof.

            Output

            You should output one possible optimal assignment. On the first line of the output write the even number C, the amount of scheduled guards. Then output C/2 lines, each containing 2 integers (ij) that denote that i and j will work together.

            Sample

            inputoutput
            3
            1 2
            2 3
            1 3
            
            2
            1 2
            
            Problem Author: Jivko Ganev



            模板題.....一般圖匹配主要看模板,剩下的就是自己YY建圖了.....

            模板:
            #include <cstdio>
            #include 
            <cstring>
            #include 
            <algorithm>
            #include 
            <iostream>
            #define MAXN 256
            using namespace std;

            struct Graph
            {
                
            bool mat[MAXN + 1][MAXN + 1];
                
            int n;

                
            bool inque[MAXN + 1];
                
            int que[MAXN], head, tail;

                
            int match[MAXN + 1], father[MAXN + 1], base[MAXN + 1];

                
            void init(int _n)
                {
                    n 
            = _n;
                    
            for (int i = 1; i <= n; ++i)
                    {
                        match[i] 
            = 0;
                        
            for (int j = 1; j <= n; ++j)
                            mat[i][j] 
            = false;
                    }
                }

                
            int pop()
                {
                    
            return que[head++];
                }

                
            void push(int x)
                {
                    que[tail
            ++= x;
                    inque[x] 
            = true;
                }

                
            void add_edge(int a, int b)
                {
                    mat[a][b] 
            = mat[b][a] = true;
                }

                
            int inpath[MAXN + 1];
                
            static int pcnt;

                
            int find_ancestor(int u, int v)
                {
                    
            ++pcnt;
                    
            while (u)
                    {
                        u 
            = base[u];
                        inpath[u] 
            = pcnt;
                        u 
            = father[match[u]];
                    }

                    
            while (true)
                    {
                        v 
            = base[v];
                        
            if (inpath[v] == pcnt)
                            
            return v;
                        v 
            = father[match[v]];
                    }
                }

                
            int inblossom[MAXN + 1];
                
            static int bcnt;

                
            void reset(int u, int anc)
                {
                    
            while (u != anc)
                    {
                        
            int v = match[u];
                        inblossom[
            base[v]] = bcnt;
                        inblossom[
            base[u]] = bcnt;
                        v 
            = father[v];
                        
            if (base[v] != anc) father[v] = match[u];
                        u 
            = v;
                    }
                }

                
            void contract(int u, int v)
                {
                    
            int anc = find_ancestor(u, v);
                    
            ++bcnt;
                    reset(u, anc);
                    reset(v, anc);
                    
            if (base[u] != anc) father[u] = v;
                    
            if (base[v] != anc) father[v] = u;
                    
            for (int i = 1; i <= n; ++i)
                        
            if (inblossom[base[i]] == bcnt)
                        {
                            
            base[i] = anc;
                            
            if (!inque[i]) push(i);
                        }
                }

                
            int find_augment(int start)
                {
                    
            for (int i = 1; i <= n; ++i)
                    {
                        father[i] 
            = 0;
                        inque[i] 
            = false;
                        
            base[i] = i;
                    }
                    head 
            = 0, tail = 0, push(start);
                    
            while (head < tail)
                    {
                        
            int u = pop();
                        
            for (int v = 1; v <= n; ++v)
                            
            if (mat[u][v] && base[v] != base[u] && match[v] != u)
                            {
                                
            if (v == start || (match[v] && father[match[v]]))
                                    contract(u, v);
                                
            else
                                {
                                    
            if (father[v] == 0)
                                    {
                                        
            if (match[v])
                                        {
                                            push(match[v]);
                                            father[v] 
            = u;
                                        }
                                        
            else
                                        {
                                            father[v] 
            = u;
                                            
            return v;
                                        }
                                    }
                                }
                            }
                    }
                    
            return 0;
                }

                
            void augment(int finish)
                {
                    
            int u = finish, v, w;
                    
            while (u)
                    {
                        v 
            = father[u];
                        w 
            = match[v];
                        match[u] 
            = v;
                        match[v] 
            = u;
                        u 
            = w;
                    }
                }

                
            int graph_max_match()
                {
                    
            int ans = 0;
                    
            for (int i = 1; i <= n; ++i)
                        
            if (match[i] == 0)
                        {
                            
            int finish = find_augment(i);
                            
            if (finish)
                            {
                                augment(finish);
                                ans 
            += 2;
                            }
                        }
                    
            return ans;
                }
            } g;

            int Graph :: bcnt = 0, Graph :: pcnt = 0;

            int main()
            {
                
            int n;
                scanf(
            "%d"&n);
                g.init(n);
                
            int a, b;
                
            while (scanf("%d%d"&a, &b) != EOF)
                    g.add_edge(a, b);
                printf(
            "%d\n", g.graph_max_match());
                
            for (int i = 1; i <= n; ++i)
                    
            if (g.match[i])
                    {
                        printf(
            "%d %d\n", i, g.match[i]);
                        g.match[g.match[i]] 
            = 0;
                    }
                
            return 0;
            }

            posted on 2011-10-15 22:16 LLawliet 閱讀(291) 評論(0)  編輯 收藏 引用 所屬分類: 圖論
            99蜜桃臀久久久欧美精品网站| 伊人久久大香线蕉影院95| 亚洲精品99久久久久中文字幕| 久久久WWW免费人成精品| 久久亚洲中文字幕精品一区| 无码日韩人妻精品久久蜜桃| 久久这里只精品国产99热| 一本色道久久88综合日韩精品 | 久久综合给合综合久久| 久久精品国产亚洲AV不卡| 热久久这里只有精品| 久久久www免费人成精品| 国产 亚洲 欧美 另类 久久| 久久婷婷五月综合97色直播| Xx性欧美肥妇精品久久久久久 | 久久精品国产99国产精品导航| 国产精品久久久久9999高清| 欧美成a人片免费看久久| 成人国内精品久久久久影院| 少妇人妻综合久久中文字幕| 国产亚洲美女精品久久久久狼| 亚洲人成无码www久久久| 伊人久久大香线蕉影院95| 久久国产欧美日韩精品| 久久丫忘忧草产品| 伊人久久大香线蕉成人| 国产99久久久国产精免费| 91精品国产综合久久精品| 亚洲人成网亚洲欧洲无码久久| 久久精品夜色噜噜亚洲A∨| 久久精品免费观看| 久久久久亚洲精品天堂| 亚洲αv久久久噜噜噜噜噜| 色综合久久夜色精品国产| 欧美一级久久久久久久大片| 中文精品久久久久国产网址| 久久久久亚洲av无码专区导航 | 亚洲中文字幕无码久久2020 | 久久精品www人人爽人人| 久久久久99精品成人片直播| 亚洲va久久久噜噜噜久久天堂 |