• <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>
            隨筆 - 87  文章 - 279  trackbacks - 0
            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            潛心看書研究!

            常用鏈接

            留言簿(19)

            隨筆分類(81)

            文章分類(89)

            相冊

            ACM OJ

            My friends

            搜索

            •  

            積分與排名

            • 積分 - 217924
            • 排名 - 117

            最新評論

            閱讀排行榜

            評論排行榜

            Girls and Boys

            Time limit: 10 Seconds?? Memory limit: 32768K??
            Total Submit: 628?? Accepted Submit: 188??

            the second year of the university somebody started a study on the romantic relations between the students. The relation “romantically involved” is defined between one girl and one boy. For the study reasons it is necessary to find out the maximum set satisfying the condition: there are no two students in the set who have been “romantically involved”. The result of the program is the number of students in such a set.

            The input contains several data sets in text format. Each data set represents one set of subjects of the study, with the following description:

            the number of students
            the description of each student, in the following format
            student_identifier:(number_of_romantic_relations) student_identifier1 student_identifier2 student_identifier3 ...
            or
            student_identifier:(0)

            The student_identifier is an integer number between 0 and n-1, for n subjects.
            For each given data set, the program should write to standard output a line containing the result.

            An example is given in Figure 1.


            Input

            7
            0: (3) 4 5 6
            1: (2) 4 6
            2: (0)
            3: (0)
            4: (2) 0 1
            5: (1) 0
            6: (2) 0 1
            3
            0: (2) 1 2
            1: (1) 0
            2: (1) 0


            Output

            5
            2

            #include? < iostream > ?
            using ? namespace ?std;

            const ? int ?MAXN? = ? 1001 ;
            int ?uN,?vN;?? // u,v數目?
            bool ?g[MAXN][MAXN]; // g[i][j]?表示?xi與yj相連?
            bool ?p[MAXN][MAXN];
            int ?xM[MAXN],?yM[MAXN];? // ?輸出量?
            bool ?chk[MAXN];? // 輔助量?檢查某輪?y[v]是否被check?

            int ?sign[MAXN];
            int ?N;

            bool ?SearchPath( int ?u)
            {
            ????
            int ?v;
            ????
            for ?(v = 0 ;?v < vN;?v ++ )
            ????
            {
            ????????
            if ?(g[u][v]? && ? ! chk[v])
            ????????
            {
            ????????????chk[v]?
            = ? true ;
            ????????????
            if ?(yM[v]? == ? - 1 ? || ?SearchPath(yM[v]))?
            ????????????
            {
            ????????????????yM[v]?
            = ?u;
            ????????????????xM[u]?
            = ?v;
            ????????????????
            return ? true ;
            ????????????}

            ????????}

            ????}

            ????
            return ? false ;
            }



            int ?MaxMatch()
            {
            ????
            int ?u;
            ????
            int ?ret? = ? 0 ;
            ????memset(xM,?
            - 1 ,? sizeof (xM));
            ????memset(yM,?
            - 1 ,? sizeof (yM));
            ????
            for ?(u = 0 ;?u < uN;?u ++ )
            ????
            {
            ????????
            if ?(xM[u]? == ? - 1 )
            ????????
            {
            ????????????memset(chk,?
            false ,? sizeof (chk));
            ????????????
            if ?(SearchPath(u))?ret ++ ;
            ????????}

            ????}

            ????
            return ?ret;
            }


            void ?SetSign( int ?v,? int ?s)
            {
            ????
            int ?i;
            ????sign[v]?
            = ?s;
            ????
            for ?(i = 0 ;?i < N;?i ++ )
            ????????
            if ?(sign[i]? == ? - 1 ? && ?p[v][i])
            ????????????SetSign(i,?
            1 - s);?????
            }


            void ?Solve()
            {
            ????
            int ?i,?j;?
            ????
            int ?tU,?tV;
            ????
            int ?num;
            ????memset(g,?
            false ,? sizeof (g));
            ????memset(p,?
            false ,? sizeof (p));
            ????memset(sign,?
            - 1 ,? sizeof (sign));
            ????
            for ?(i = 0 ;?i < N;?i ++ )
            ????
            {
            ????????scanf(
            " \n%d:?(%d) " ,? & tU,? & num);
            ????????
            for ?(j = 0 ;?j < num;?j ++ )
            ????????
            {
            ????????????scanf(
            " %d " ,? & tV);
            ????????????p[tU][tV]?
            = ? true ;
            ????????}

            ????}
            ?
            ????
            ????
            // -------------DFS標號法(劃分二分圖)--------------------?
            ???? /* ******************************************
            ????鄰接表的DFS標號:
            ????void?setmark(int?v,int?sign)
            ????{
            ????????sig[v]=sign;
            ????????int?i;
            ????????for?(i=0;i<nu[v];i++)
            ????????????if?(!sig[d[v][i]])
            ????????????????setmark(d[v][i],sign^3);
            ????}?
            ????for?(v=0;v<n;v++)
            ????????if?(!sig[v])?setmark(v,1);
            ????*******************************************
            */

            ????
            for ?(i = 0 ;?i < N;?i ++ )
            ????????
            if ?(sign[i]? == ? - 1 )?SetSign(i,? 1 );
            ????
            // ------------------------------------------????
            ????????
            ????
            for ?(i = 0 ;?i < N;?i ++ )
            ????
            {
            ????????
            if ?(sign[i]? == ? 1 )
            ????????
            {
            ????????????
            for ?(j = 0 ;?j < N;?j ++ )
            ????????????????
            if ?(p[i][j])?g[i][j]? = ? true ;
            ????????}

            ????}
            ????????????
            ????uN?
            = ?vN? = ?N;
            ????printf(
            " %d\n " ,?N - MaxMatch());?
            }
            ?

            int ?main()
            {
            ????
            while ?(scanf( " %d " ,? & N)? != ?EOF)
            ????
            {
            ????????Solve();
            ????}

            ????
            return ? 0 ;
            }

            posted on 2006-10-01 22:53 閱讀(582) 評論(0)  編輯 收藏 引用 所屬分類: ACM題目
            综合网日日天干夜夜久久| 亚洲成色www久久网站夜月| 国产精品久久久久影院色| 亚洲国产精品久久| 久久av免费天堂小草播放| 国产精品中文久久久久久久| 亚洲AV无码1区2区久久| 国产精品免费看久久久香蕉| 久久久久久国产精品无码下载 | 超级碰碰碰碰97久久久久| 色婷婷久久综合中文久久蜜桃av| 久久精品国产亚洲av日韩| 久久人搡人人玩人妻精品首页| 亚洲国产一成人久久精品| 国产一区二区精品久久凹凸| 国产A三级久久精品| 久久精品亚洲欧美日韩久久| 丰满少妇高潮惨叫久久久| 久久无码AV一区二区三区| 久久精品一区二区| 久久久久99精品成人片欧美| 欧美与黑人午夜性猛交久久久 | 国产精品久久成人影院| 中文字幕精品无码久久久久久3D日动漫 | 久久精品国产亚洲AV麻豆网站| 一本综合久久国产二区| 久久精品国产99久久久香蕉| 久久精品国产免费一区| 久久ZYZ资源站无码中文动漫| 欧美精品国产综合久久| 性做久久久久久免费观看| 激情久久久久久久久久| 国产真实乱对白精彩久久| 狠狠久久亚洲欧美专区| 久久国产乱子伦免费精品| 亚洲va中文字幕无码久久| 伊人久久大香线蕉亚洲| 亚洲av日韩精品久久久久久a | 亚洲国产精品久久久久久| 久久99精品国产| 久久精品国产黑森林|