티스토리 뷰

반응형


Difficulty : 4/10

I couln't solve this problem during the contest.
but It is not a difficult probelm.

this problem can be solved in various way. I solved it with "union find algorithm". because union find is good algorithms to express "disjoint set".

but the problem has a constraint. It is a "all station has just two degree, Just in and out".
so it can be solved with just loop using parent, visit array.

these two problem solving has different time complexity each other. second one is faster and use less memory. but when express disjoint set, union find is common one.


union find
Source:


loop
Source:



반응형

'알고리즘 문제 > DFS and Simillar' 카테고리의 다른 글

백준 12784 인하니카 공화국  (0) 2018.05.29
백준 2447 별찍기10  (0) 2018.03.06
BoJ 1717 : 집합의 표현  (0) 2017.10.29