one day is too short to understand that
because I have to know union and find algorithm in first.
using it we can find whether this would be circle or not if we connect tree and one point.
It was hard to write java but i tried.
Precondition: all items are numbered and unique
refereced by http://www.algorithmist.com/index.php/Union_Find
If you have any question, comment Plz~
if my code is show how stange. reply and discuss
pseudo code is Below
func find( var element ) while ( element is not the root ) element = element's parent return element end func func union( var setA, var setB ) var rootA = find( setA ), rootB = find( setB ) if ( rootA is equal to rootB ) return else set rootB as rootA's parent end func