並查集 Union-Find
16 題(14 題以此為主技法)
🎯 何時用
動態合併集合、查詢連通性、偵測無向圖環、Kruskal。
🧩 模板心法
find 路徑壓縮 + union by rank/size,近 O(1) 攤還;計分量數隨 union 遞減。
Medium 12 題
- #128Longest Consecutive Sequence
- #200Number of Islands
- #261Graph Valid Tree
- #323Number of Connected Components in an Undirected Graph
- #130Surrounded Regions
- #684Redundant Connection
- #721Accounts Merge
- #399Evaluate Division
- #785Is Graph Bipartite?
- #1905Count Sub Islands
- #2492Minimum Score of a Path Between Two Cities
- #1631Path with Minimum Effort