after class (based on Nick Belov's idea and top of p. 49 of Robin Wilson's book) #AntiPC(P): inputs a list of length n-2 with entries from {1, ...,n} outputs the tree with #labels {1, ...,n} whose Pruffer code is P AntiPC:=proc(P) local n,V,i,P1,b1,E: n:=nops(P)+2: V:={seq(i,i=1..n)}: P1:=P: E:={}: while P1<>[] do b1:=min (V minus convert(P1,set)): E:=E union {{P1[1],b1}}: P1:=[op(2..nops(P1),P1)]: V:=V minus {b1}: od: E union {V}: end: