๊ด€๋ฆฌ ๋ฉ”๋‰ด

๋ชฉ๋ก์œ ๋‹ˆ์˜จ ํŒŒ์ธ๋“œ (1)

JUINTINATION

์œ ๋‹ˆ์˜จ ํŒŒ์ธ๋“œ(Union-Find)

์„œ๋กœ์†Œ ์ง‘ํ•ฉ(Disjoint Set)์ด๋ž€? ๊ณตํ†ต ์›์†Œ๊ฐ€ ์—†๋Š” ๋‘ ์ง‘ํ•ฉ, ์ฆ‰ A∩B=∅์„ ๋งŒ์กฑ์‹œํ‚ค๋Š” ๋‘ ์ง‘ํ•ฉ A, B๋ฅผ ์„œ๋กœ์†Œ ์ง‘ํ•ฉ์ด๋ผ๊ณ  ํ•œ๋‹ค. ์œ ๋‹ˆ์˜จ ํŒŒ์ธ๋“œ(Union-Find)๋ž€? ์„œ๋กœ์†Œ ์ง‘ํ•ฉ์— ๋Œ€ํ•œ ์—ฐ์‚ฐ์„ ํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด๋‹ค. ์‰ฌ์šด ์ดํ•ด๋ฅผ ์œ„ํ•ด ๋‹ค์Œ์˜ ์˜ˆ์‹œ๋ฅผ ๋ณด์ž. https://www.acmicpc.net/problem/1717 1717๋ฒˆ: ์ง‘ํ•ฉ์˜ ํ‘œํ˜„ ์ดˆ๊ธฐ์— $n+1$๊ฐœ์˜ ์ง‘ํ•ฉ $\{0\}, \{1\}, \{2\}, \dots , \{n\}$์ด ์žˆ๋‹ค. ์—ฌ๊ธฐ์— ํ•ฉ์ง‘ํ•ฉ ์—ฐ์‚ฐ๊ณผ, ๋‘ ์›์†Œ๊ฐ€ ๊ฐ™์€ ์ง‘ํ•ฉ์— ํฌํ•จ๋˜์–ด ์žˆ๋Š”์ง€๋ฅผ ํ™•์ธํ•˜๋Š” ์—ฐ์‚ฐ์„ ์ˆ˜ํ–‰ํ•˜๋ ค๊ณ  ํ•œ๋‹ค. ์ง‘ํ•ฉ์„ ํ‘œํ˜„ํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘ www.acmicpc.net ์œ„์˜ ๋ฌธ์ œ์ฒ˜๋Ÿผ ์ดˆ๊ธฐ์— n+1๊ฐœ์˜ ์ง‘ํ•ฉ {0}, {1}, {2}, ... , {n}์ด..