====== 집합의 표현 ====== ===== 풀이 ===== * [[ps:Disjoint set]]의 기본 연산을 구현하는 튜토리얼적인 문제. 그냥 Disjoint Set을 구현해서 Union과 Find 연산을 사용하면 된다 * 시간복잡도는 O(m*α(n)) ===== 코드 ===== """Solution code for "BOJ 1717. 집합의 표현". - Problem link: https://www.acmicpc.net/problem/1717 - Solution link: http://www.teferi.net/ps/problems/boj/1717 Tags: [DisjointSet] """ import sys from teflib import disjointset def main(): # pylint: disable=unused-variable n, m = [int(x) for x in sys.stdin.readline().split()] dsu = disjointset.DisjointSet(n + 1) for _ in range(m): oper, a, b = [int(x) for x in sys.stdin.readline().split()] if oper == 0: dsu.union(a, b) else: print('YES' if dsu.find(a) == dsu.find(b) else 'NO') if __name__ == '__main__': main() * Dependency: [[:ps:teflib:disjointset#DisjointSet|teflib.disjointset.DisjointSet]] {{tag>BOJ ps:problems:boj:골드_4}}