Sasha take programming competition in problem check rooted tree isomorphic she see problem experience participant guess match tree sequence compare sequence instead tree Sasha want match tree sequence a0a1ah h height tree ai equal number vertex distance edge root unfortunately time Sashas intuition wrong tree match sequence to need write program give sequence ai build nonisomorphic root tree match sequence determine treetwo rooted tree isomorphic reenumerate vertex way index root equal index root second tree tree equalthe height root tree maximum number edge path root vertex