跳到正文

个人记录

并查集

litjohn约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年5月12日
收录
2025年12月12日
更新
2026年11月12日
篇幅
约 1 分钟

版本

  1. v1当前
lisp
(define fa (make-vector 100000 -1))
(define (find x)
    (cond ((= -1 (vector-ref fa x)) x)
      (else (let
              ((root (find (vector-ref fa x))))
              (vector-set! fa x root)
              root)
        )
      )
    )
(define (merge x y)
    (let
      ((fx (find x))
       (fy (find y)))
       (vector-set! fa fx fy)))
原文