class_docstr: The Prufer correspondence is an algorithm that describes the
  bijection between labeled trees and the Prufer code. A Prufer
  code of a labeled tree is unique up to isomorphism and has
  a length of n - 2.
  
  Prufer sequences were first used by Heinz Prufer to give a
  proof of Cayley's formula.
  
  References
  ==========
  
  .. [1] https://mathworld.wolfram.com/LabeledTree.html
class_docstr_tok: ["The","Prufer","correspondence","is","an","algorithm","that","describes","the","bijection","between","labeled","trees","and","the","Prufer","code",".","A","Prufer","code","of","a","labeled","tree","is","unique","up","to","isomorphism","and","has","a","length","of","n","-","2",".","Prufer","sequences","were","first","used","by","Heinz","Prufer","to","give","a","proof","of","Cayley","'s","formula",".","References","==========","..","[","1","]","https",":","\/\/mathworld.wolfram.com\/LabeledTree.html"]
docstr: Return the tree (as a list of edges) of the given Prufer sequence.
  
  Examples
  ========
  
  >>> from sympy.combinatorics.prufer import Prufer
  >>> a = Prufer([0, 2], 4)
  >>> a.tree_repr
  [[0, 1], [0, 2], [2, 3]]
  >>> Prufer.to_tree([0, 2])
  [[0, 1], [0, 2], [2, 3]]
  
  References
  ==========
  
  .. [1] https://hamberg.no/erlend/posts/2010-11-06-prufer-sequence-compact-tree-representation.html
  
  See Also
  ========
  tree_repr: returns tree representation of a Prufer object.
docstr_tok: ["Return","the","tree","(","as","a","list","of","edges",")","of","the","given","Prufer","sequence",".","Examples","========",">",">",">","from","sympy.combinatorics.prufer","import","Prufer",">",">",">","a","=","Prufer","(","[","0",",","2","]",",","4",")",">",">",">","a.tree_repr","[","[","0",",","1","]",",","[","0",",","2","]",",","[","2",",","3","]","]",">",">",">","Prufer.to_tree","(","[","0",",","2","]",")","[","[","0",",","1","]",",","[","0",",","2","]",",","[","2",",","3","]","]","References","==========","..","[","1","]","https",":","\/\/hamberg.no\/erlend\/posts\/2010-11-06-prufer-sequence-compact-tree-representation.html","See","Also","========","tree_repr",":","returns","tree","representation","of","a","Prufer","object","."]
code: def to_tree(prufer):
      """Return the tree (as a list of edges) of the given Prufer sequence.
  
      Examples
      ========
  
      >>> from sympy.combinatorics.prufer import Prufer
      >>> a = Prufer([0, 2], 4)
      >>> a.tree_repr
      [[0, 1], [0, 2], [2, 3]]
      >>> Prufer.to_tree([0, 2])
      [[0, 1], [0, 2], [2, 3]]
  
      References
      ==========
  
      .. [1] https://hamberg.no/erlend/posts/2010-11-06-prufer-sequence-compact-tree-representation.html
  
      See Also
      ========
      tree_repr: returns tree representation of a Prufer object.
  
      """
      tree = []
      last = []
      n = len(prufer) + 2
      d = defaultdict(lambda: 1)
      for p in prufer:
          d[p] += 1
      for i in prufer:
          for j in range(n):
              # find the smallest leaf (degree = 1)
              if d[j] == 1:
                  break
          # (i, j) is the new edge that we append to the tree
          # and remove from the degree dictionary
          d[i] -= 1
          d[j] -= 1
          tree.append(sorted([i, j]))
      last = [i for i in range(n) if d[i] == 1] or [0, 1]
      tree.append(last)
  
      return tree
  
imports: from sympy.core import Basic
  from sympy.core.containers import Tuple
  from sympy.tensor.array import Array
  from sympy.core.sympify import _sympify
  from sympy.utilities.iterables import flatten, iterable
  from sympy.utilities.misc import as_int
  from collections import defaultdict
label_desc: Use image node_id 7 for calling the Prufer obj's underlying member method code with example usage: obj.to_tree(prufer) and returns: tree