| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
谁能给组测试数据啊?2492 都过了,这道怎么过不了#include <cstdio>
#include <cstdlib>
int n,m,a,b,i,j,count = 0;
int p[100002],ch[100002];
void Make_set()
{
for(i = 1; i <= n; ++i)
{
p[i] = i;
ch[i] = 0;
}
}
int Find_set(int x)
{
int t;
if(x == p[x])
return x;
t = Find_set(p[x]);
ch[x] = (ch[x] + ch[p[x]]) % 2;
p[x] = t;
return t;
}
int Check(int x,int y)
{
int px,py;
count = 0;
px = Find_set(x);
py = Find_set(y);
if(px == py)
{
if(ch[x] == ch[y])
{
count = 1;
return count;
}
else
{
count = -1;
return count;
}
}
p[px] = py;
ch[px] = (ch[x] - ch[y] + 1) % 2;
return count;
}
int main()
{
int t,res;
char c;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
getchar();
Make_set();
while(m--)
{
scanf("%c%d%d",&c,&a,&b);
if(c == 'D')
{
Check(a,b);
}
else if(c == 'A')
{
res = Check(a,b);
if(!res)
printf("Not sure yet.\n");
else if(res > 0)
printf("In the same gang.\n");
else
printf("In different gangs.\n");
}
getchar();
}
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator