a tree undirecte connect graph cycleslet consider root undirected tree n vertex number 1 n there way represent tree one way create array n integer p1p2pn pi denote parent vertex convenience root consider parent for rooted tree array p 2332 give sequence p1p2pn able restore tree there exactly index r prr a vertex r root tree for n1 vertex edge vertex vertex pi a sequence p1p2pn call valid describe procedure generate rooted tree for example n3 sequence 122 231 213 validYou give sequence a1a2an necessarily valid your task change minimum number element order valid sequence print minimum number change example valid sequence number change if valid sequence achievable minimum number change print