LoginSignup
0
0

More than 5 years have passed since last update.

[アルゴリズム演習] UnionFind木

Posted at

UnionFind木を完成させよ。

  • グループ分けを管理するデータ構造。
  • 要素aと要素bが同じグループかどうかを調べる。
  • 要素aと要素bのグループを併合する。
  • 配列(parent)で親を管理。
  • 追加(Add):最後にユニークな値を入れる。
  • 併合(Union):片方のグループの木の根からもう片方のグループの木の根をはる。
  • 判定(IsSame):親をたどり各々の根が同じかどうかを見る。
  • 根を調べる(Find):親をたどる。
public class UnionFind
{
    private List<int> parent = new List<int>();
    public void Add() { ... }
    public bool IsSame(int i, int j) { ... }
    public int Find(int i) { ... }
    public void Unite(int a, int b) { ... }
}
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0