摘要: 维护一个relation数组,保留着此元素和根元素之间的性别关系。之后就可以判断gay了。 #include <cstdio> #include <algorithm> #include <cstring> using namespace std; const int maxn=2010; int 阅读全文
posted @ 2016-02-02 00:07 Helica 阅读(203) 评论(0) 推荐(0)
摘要: 记录元素个数的并查集。 利用sz数组保存并查集的大小。每次union时,把小的集合并到大的中去,并更新sz数组。 #include <cstdio> #include <algorithm> using namespace std; int n,m,k; int fa[30010],sz[30010 阅读全文
posted @ 2016-02-02 00:03 Helica 阅读(221) 评论(0) 推荐(0)
摘要: 模板题 对于每修复一台终端,就遍历所有其他已修复的终端,如果距离在d之内,就union。 之后看是否在一个并查集中。 #include <cstdio> #include <algorithm> #include <cstring> using namespace std; int N,D,pos[ 阅读全文
posted @ 2016-02-02 00:01 Helica 阅读(172) 评论(0) 推荐(0)