Addition of the solution for 10507 Waking up brain problem (union-find set).