poj 1703 Find them, Catch them(种类并查集)
2014-08-15 17:08
330 查看
Findthem,Catchthem
DescriptionThepoliceofficeinTaduCitydecidestosayendstothechaos,aslaunchactionstorootuptheTWOgangsinthecity,GangDragonandGangSnake.However,thepolicefirstneedstoidentifywhichgangacriminalbelongsto.Thepresentquestionis,giventwocriminals;dotheybelongtoasameclan?Youmustgiveyourjudgmentbasedonincompleteinformation.(Sincethegangstersarealwaysactingsecretly.)AssumeN(N<=10^5)criminalsarecurrentlyinTaduCity,numberedfrom1toN.Andofcourse,atleastoneofthembelongstoGangDragon,andthesameforGangSnake.YouwillbegivenM(M<=10^5)messagesinsequence,whichareinthefollowingtwokinds:1.D[a][b]where[a]and[b]arethenumbersoftwocriminals,andtheybelongtodifferentgangs.2.A[a][b]where[a]and[b]arethenumbersoftwocriminals.Thisrequiresyoutodecidewhetheraandbbelongtoasamegang.InputThefirstlineoftheinputcontainsasingleintegerT(1<=T<=20),thenumberoftestcases.ThenTcasesfollow.EachtestcasebeginswithalinewithtwointegersNandM,followedbyMlineseachcontainingonemessageasdescribedabove.OutputForeachmessage"A[a][b]"ineachcase,yourprogramshouldgivethejudgmentbasedontheinformationgotbefore.Theanswersmightbeoneof"Inthesamegang.","Indifferentgangs."and"Notsureyet."SampleInput
TimeLimit:1000MS | MemoryLimit:10000K | |
TotalSubmissions:31532 | Accepted:9713 |
1 55 A12 D12 A12 D24 A14SampleOutput
Notsureyet. Indifferentgangs. Inthesamegang.
题意:警察要肃清两个帮派,该城市有龙帮和蛇帮两个帮派,给出两个罪犯,让我们判断是否属于一个帮派。
当前有N(1-N)个罪犯在这个城市,至少他们其中一个属于龙帮或者蛇帮,给出M行信息,信息分两种:
1.D[a][b]:a和b罪犯不属于同一个帮派。
2.A[a][b]:判断a和b是不是在一个帮派。是就输出Inthesamegang.不是就输出Indifferentgangs.不能判断就输出Notsureyet.
分析:种类并查集;
两个数组,一个为储存根节点的数组,另外一个为储存该点与根节点之间的关系(0,或者1)在寻找根节点的时候需要更新该点与根节点之间的关系;x与y合并的时候,若x1为y1的根节点,那么需要求ans[y1];
ans[y1]=(ans[x]-ans[y]+1)%2;如下图所示可得出
相关文章推荐
- POJ 1703 - Find them, Catch them(种类并查集)
- POJ 1703 Find them, Catch them 种类并查集
- POJ 1703 Find them, Catch them(种类并查集)
- POJ 1703 Find them, Catch them【带种类的并查集】
- POJ 1703 Find them,Catch them ----种类并查集(经典)
- POJ 1703 Find them,Catch them ----种类并查集(经典)
- POJ:1703-Find them, Catch them(并查集好题)(种类并查集)
- poj 1703 Find them, Catch them 带权并查集OR种类并查集
- poj 1703 Find them, Catch them(种类并查集)
- POJ 1703 Find them, Catch them(种类并查集)
- POJ 1703 Find them, Catch them 种类并查集(入门)
- POJ - 1703 Find them, Catch them(种类并查集)
- POJ:1703 Find them, Catch them(种类并查集(影子并查集))
- POJ1703--Find them, Catch them(种类并查集)
- poj 1703 Find them, Catch them(种类并查集和一种巧妙的方法)
- poj 1703 Find them, Catch them(种类并查集和一种巧妙的方法)
- POJ 1703 Find them, Catch them(种类并查集)
- POJ 1703 Find them, Catch them(种类并查集)
- poj 1703 Find them, Catch them (种类并查集)
- poj1703 Find them, Catch them(种类并查集