code: def acyclic_branches_depth_first(
      tree, children=iter, depth=-1, cut_mark=None, traversed=None
  ):
      """Traverse the nodes of a tree in depth-first order,
      discarding eventual cycles within the same branch,
      but keep duplicate paths in different branches.
      Add cut_mark (when defined) if cycles were truncated.
  
      The first argument should be the tree root;
      children should be a function taking as argument a tree node
      and returning an iterator of the node's children.
  
      Catches only only cycles within the same branch,
      but keeping cycles from different branches:
  
      >>> import nltk
      >>> from nltk.util import acyclic_branches_depth_first as tree
      >>> wn=nltk.corpus.wordnet
      >>> from pprint import pprint
      >>> pprint(tree(wn.synset('certified.a.01'), lambda s:s.also_sees(), cut_mark='...', depth=4))
      [Synset('certified.a.01'),
       [Synset('authorized.a.01'),
        [Synset('lawful.a.01'),
         [Synset('legal.a.01'),
          "Cycle(Synset('lawful.a.01'),0,...)",
          [Synset('legitimate.a.01'), '...']],
         [Synset('straight.a.06'),
          [Synset('honest.a.01'), '...'],
          "Cycle(Synset('lawful.a.01'),0,...)"]],
        [Synset('legitimate.a.01'),
         "Cycle(Synset('authorized.a.01'),1,...)",
         [Synset('legal.a.01'),
          [Synset('lawful.a.01'), '...'],
          "Cycle(Synset('legitimate.a.01'),0,...)"],
         [Synset('valid.a.01'),
          "Cycle(Synset('legitimate.a.01'),0,...)",
          [Synset('reasonable.a.01'), '...']]],
        [Synset('official.a.01'), "Cycle(Synset('authorized.a.01'),1,...)"]],
       [Synset('documented.a.01')]]
      """
      if traversed is None:
          traversed = {tree}
      out_tree = [tree]
      if depth != 0:
          try:
              for child in children(tree):
                  if child not in traversed:
                      # Recurse with a different "traversed" set for each child:
                      out_tree += [
                          acyclic_branches_depth_first(
                              child,
                              children,
                              depth - 1,
                              cut_mark,
                              traversed.union({child}),
                          )
                      ]
                  else:
                      warnings.warn(
                          "Discarded redundant search for {} at depth {}".format(
                              child, depth - 1
                          ),
                          stacklevel=3,
                      )
                      if cut_mark:
                          out_tree += [
                              f"Cycle({child},{depth - 1},{cut_mark})"
                          ]
          except TypeError:
              pass
      elif cut_mark:
          out_tree += [cut_mark]
      return out_tree
  
imports: import inspect
  import locale
  import os
  import pydoc
  import re
  import textwrap
  import unicodedata
  import warnings
  from collections import defaultdict, deque
  from itertools import chain, combinations, islice, tee
  from pprint import pprint
  from urllib.request import HTTPPasswordMgrWithDefaultRealm, ProxyBasicAuthHandler, ProxyDigestAuthHandler, ProxyHandler, build_opener, getproxies, install_opener
  from nltk.collections import *
  from nltk.internals import deprecated, raise_unorderable_types, slice_bounds
label_desc: Use image node_id 15 for calling a global function with example usage: acyclic_branches_depth_first(tree, children, depth, cut_mark, traversed) and returns: out_tree