I'm OWenT

Challenge Everything

#
  • Home
  • Archives
  • About

并查集 模板

//并查集
//注意类型匹配
const int maxn = 100002;
int DSet[maxn];
void init(int n) {
    for(int i = 0 ; i <= n ; i ++)
        DSet[i] = i;
}
int findP(int id) {
if(DSet[id] != id)
    DSet[id] = findP(DSet[id]);
    return DSet[id];
}
//返回根节点ID
int UnionEle(int a,int b) {
    a = findP(a);
    b = findP(b);
    if(a > b)
        a ^= b ^= a ^= b;
    DSet[b] = a;
    return a;
}
  1. Article
  2. My ACM-ICPC Career
2009-07-15
  • acm
  • template

  • 上一篇POJ 3267 The Cow Lexicon 解题报告
  • 下一篇模式匹配(kmp)个人模板

知识共享许可协议 2026 OWenT
沪ICP备2022003252号 本站源码 发布者 Hugo 主题 distinctionpp