17352번 (유니온파인드)
·
CS 이론/알고리즘
https://www.acmicpc.net/problem/17352 union_root(1,3)-> parent = [0,2,3,3,4] 부모 노드를 정의한다. find_root(1) -> [0, 3, 3, 3, 4] find_root(2) -> [0, 3, 3, 3, 4]으로 정의되어서 1과 4의 root가 달라서 1 4를 출력한다. public void union_root(int x, int y){ x=find_root(x); y=find_root(y); if(x!=y){ parent[x]=y; } } public int find_root(int x){ if(x==parent[x]) return x; return parent[x]=find_root(parent[x]); } 그래서 union_root는..