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 |
Re:wa 得没边了 ,那位大神帮我看看In Reply To:wa 得没边了 ,那位大神帮我看看 Posted by:w2006 at 2019-07-13 20:57:27 > #include<cstdio> > #include<cstring> > const int N=110000; > int t,n,m; > char c; > int a,b; > int f[N]; > int e[N]; > bool flag; > bool f1,f2; > int get1(int x){ > if(f[x]!=x) f[x]=get1(f[x]); > return f[x]; > } > int main(){ > > //freopen("poj1703.in","r",stdin); > scanf("%d",&t); > while(t--){ > scanf("%d%d\n",&n,&m); > flag=false; > f1=false; > f2=false; > if(n==2) flag=true; > for(int i=1;i<=n;i++) f[i]=i; > memset(e,-1,sizeof e); > for(int i=1;i<=m;i++){ > scanf("%c%d%d\n",&c,&a,&b); > //printf("%c %d %d\n",c,a,b); > > if(c=='D'){ > int a1=get1(a); > int b1=get1(b); > flag=false; > if(e[a1]!=-1) f[b1]=get1(e[a1]); > if(e[b1]!=-1) f[a1]=get1(e[b1]); > e[a1]=b1; > e[b1]=a1; > } > else{ > int a1=get1(a); > int b1=get1(b); > if(flag == true){ > printf("In different gangs.\n"); > continue; > } > if(a1==b1) printf("In the same gang.\n"); > else if(e[a1]==b1 or e[b1]==a1) printf("In different gangs.\n"); > else printf("Not sure yet.\n"); > } > } > > //for(int i=1;i<=n;i++) printf("%d ",e[i]); > } > > > return 0; > > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator