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

            poj1073

            Find them, Catch them

            Time Limit: 1000MS Memory Limit: 10000K
            Total Submissions: 21467 Accepted: 6371

            Description

            The police office in Tadu City decides to say ends to the chaos, as launch actions to root up the TWO gangs in the city, Gang Dragon and Gang Snake. However, the police first needs to identify which gang a criminal belongs to. The present question is, given two criminals; do they belong to a same clan? You must give your judgment based on incomplete information. (Since the gangsters are always acting secretly.)

            Assume N (N <= 10^5) criminals are currently in Tadu City, numbered from 1 to N. And of course, at least one of them belongs to Gang Dragon, and the same for Gang Snake. You will be given M (M <= 10^5) messages in sequence, which are in the following two kinds:

            1. D [a] [b]
            where [a] and [b] are the numbers of two criminals, and they belong to different gangs.

            2. A [a] [b]
            where [a] and [b] are the numbers of two criminals. This requires you to decide whether a and b belong to a same gang.

            Input

            The first line of the input contains a single integer T (1 <= T <= 20), the number of test cases. Then T cases follow. Each test case begins with a line with two integers N and M, followed by M lines each containing one message as described above.

            Output

            For each message "A [a] [b]" in each case, your program should give the judgment based on the information got before. The answers might be one of "In the same gang.", "In different gangs." and "Not sure yet."

            Sample Input

            1
            5 5
            A 1 2
            D 1 2
            A 1 2
            D 2 4
            A 1 4
            

            Sample Output

            Not sure yet.
            In different gangs.
            In the same gang.
            

            Source

            POJ Monthly--2004.07.18

            囧,知道是并查集
            也知道是根據路徑長度判斷是不是一個集合
            但是 剛開始發現不能路徑壓縮,然后就裸的了,就tle了

            然后………
            寫了一串不知道是什么東西的東西,然后就過了
            #include <cstdio>
            #include 
            <cstdlib>
            #include 
            <cstring>
            #include 
            <cmath>
            #include 
            <ctime>
            #include 
            <cassert>
            #include 
            <iostream>
            #include 
            <sstream>
            #include 
            <fstream>
            #include 
            <map>
            #include 
            <set>
            #include 
            <vector>
            #include 
            <queue>
            #include 
            <algorithm>
            #include 
            <iomanip>
            #define maxn 100005
            using namespace std;
            int father[maxn];
            int mark[maxn];
            int n,m;
            int find(int x)
            {
                
            if(father[x]==x) return x;
                
            else
                
            {
                   
            int  pa=father[x];
                    father[x]
            =find(father[x]);
                    mark[x]
            =!(mark[x]^mark[pa]);
                    
            return father[x];
                }

            }

            void unit(int x,int y)
            {
                
            int r1,r2;
                r1
            =find(x);
                r2
            =find(y);
                father[r1]
            =r2;
                mark[r1]
            =!((!(mark[x]^0))^mark[y]);
            }

            void cas_init()
            {
                
            for(int i=1; i<=maxn; i++) father[i]=i,mark[i]=1;
            }

            int main()
            {
                
            int x,y,t,tmp1,tmp2,len1,len2;
                
            char str[5];
                scanf(
            "%d",&t);
                
            while(t--)
                
            {
                    cas_init();
                    scanf(
            "%d%d",&n,&m);
                    
            for(int i=1; i<=m; i++)
                    
            {
                        scanf(
            "%s%d%d",str,&x,&y);
                        
            if(str[0]=='A')
                        
            {
                            tmp1
            =find(x);
                            tmp2
            =find(y);
                            
            if(tmp1==tmp2)
                            
            {
                                
            if(mark[x]==mark[y])
                                    printf(
            "In the same gang.\n");
                                
            else printf("In different gangs.\n");
                            }

                            
            else printf("Not sure yet.\n");
                        }

                        
            else if(str[0]=='D')
                        
            {
                            unit(x,y);
                        }

                    }

                }

                
            return 0;
            }




            posted on 2012-07-24 18:46 jh818012 閱讀(285) 評論(0)  編輯 收藏 引用

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

            導航

            統計

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當于是 取余3的意思 因為 3 的 二進制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄]
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評論內容較長,點擊標題查看
            • --王私江
            久久中文字幕一区二区| 国产69精品久久久久9999APGF| 一日本道伊人久久综合影| 中文字幕无码久久人妻| 国产精品一久久香蕉国产线看| 一本色综合网久久| 99久久精品国产毛片| 亚洲欧美日韩中文久久| 亚洲精品视频久久久| 久久99精品久久久久久久不卡| 思思久久99热只有频精品66| 日韩精品久久久久久| 久久国产热精品波多野结衣AV| 伊人久久一区二区三区无码| 日韩乱码人妻无码中文字幕久久| 久久久久久久久66精品片| 久久久久亚洲精品男人的天堂| 国产91色综合久久免费分享| 69久久精品无码一区二区| 久久夜色撩人精品国产| 性欧美大战久久久久久久| 麻豆亚洲AV永久无码精品久久| 97久久精品人妻人人搡人人玩| 999久久久免费精品国产| 99热都是精品久久久久久| 久久一区二区三区免费| 午夜精品久久久久久99热| 99精品伊人久久久大香线蕉| 精品久久人人做人人爽综合| 国产亚洲精久久久久久无码77777 国产亚洲精品久久久久秋霞 | 婷婷久久综合九色综合绿巨人 | 香蕉久久夜色精品国产尤物| 久久精品国产免费观看| 久久亚洲国产午夜精品理论片| 久久久免费观成人影院| 国内精品久久久久久久97牛牛 | 99久久精品国产高清一区二区| 久久夜色撩人精品国产| 狠狠色丁香久久婷婷综| 91精品国产高清91久久久久久| 国产精品99久久久精品无码|