본문 바로가기
라이브러리/자료구조

DSU

by 유시은 2021. 3. 22.
int dsfind(int tar) {
  if (tar == root[tar]) return tar;
  return root[tar] = dsfind(root[tar]);
}
void dsmerge(int a, int b) {
  a = dsfind(a), b = dsfind(b);
  if (a != b) root[a] = b;
}

 

'라이브러리 > 자료구조' 카테고리의 다른 글

Segment tree  (0) 2021.08.12
BIT  (0) 2021.03.22
Tree  (0) 2020.08.06

댓글