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 |
强烈BS自己,居然把相同时的gang加了个s,wa N次 In the same gang, 无s!具体做法并查集。我有两个数组,fa[],和to[], 输入D a b,fa[]初始化为-1,to[a]=b,to[b]=a; 当a,b第一次出现fa[a]=a,fa[b]=a,to[a]=b,to[b]=a; 当a,b有一个已经出现过了(假设a),就把b和to[Find(a)]合并; 。。。 输入A a b i=Find(a),j=Find(b); if (i!=-1&&j!=-1&&(Find(to[i])==j||Find(to[j])==i)) printf("In different gangs.\n"); else if (i==j&&i!=-1) printf("In the same gang.\n"); else printf("Not sure yet.\n"); Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator