演算法›Ch4 圖論演算法
第 109 題/共 111 題
◀ AL 109/111
109. Union-Find、Disjoint Set
#AL-04-109中Union-FindDisjoint Set

(12%) For a set of variables x1,x2,…,xnx_1, x_2, \ldots, x_n, you are given some equality constraints, of the form "xi=xjx_i = x_j" and some disequality constraints, of the form "xi≠xjx_i \ne x_j". Is it possible to satisfy all of them? For instance, the constraints:

x1=x2,x2=x3,x3=x4,x1≠x4x_1 = x_2, x_2 = x_3, x_3 = x_4, x_1 \ne x_4

cannot be satisfied. Give an efficient algorithm that takes as input m constraints over n variables and decides whether the constraints can be satisfied. Describe the data structure used by your algorithm, and analysis the time complexity of your algorithm.

📄 中央111
跳轉到第題
▤完整推導請見《WH 資工筆記 · 演算法》Ch4 圖論演算法
本章題號 · 101–111 / 111