class eulertour """abstract base class for performing euler tour of tree hook previsit and hook postvisit may be overridden by subclasses "" def init (selftree) """prepare an euler tour template for given tree "" self tree tree def tree(self) """return reference to the tree being traversed "" return self tree def execute(self) """perform the tour and return any result from post visit of root "" if len(self tree start the recursion return self tour(self tree root) ] def tour(selfpdpath) """perform tour of subtree rooted at position position of current node being visited depth of in the tree path list of indices of children on path from root to """pre visitp self hook previsit(pdpath results path append( add new index to end of path before recursion for in self tree children( )recur on child subtree results append(self tour(cd+ path) path[- + increment index path popremove extraneous index from end of path "post visitp answer self hook postvisit(pdpathresults return answer can be overridden def hook previsit(selfpdpath) pass can be overridden def hook postvisit(selfpdpathresults) pass code fragment an eulertour base class providing framework for performing euler tour traversals of tree