optimize by using stream.
min heap.
union find.
read books.