

"""simple docstring"""



from __future__ import annotations

from collections import deque
from collections.abc import Sequence
from dataclasses import dataclass
from typing import Any



@dataclass
class 					a						:



    """simple docstring"""



    UpperCAmelCase						 =					42
    UpperCAmelCase						 =					None
    UpperCAmelCase						 =					None





def  _snake_case     (    ):
     A__										=  Node(1			)
     A__										=  Node(2			)
     A__										=  Node(3			)
     A__										=  Node(4			)
     A__										=  Node(5			)
     return tree





def  _snake_case     (    UpperCAmelCase_  :					Node | None			):
     return [root.data, *preorder(root.left			), *preorder(root.right			)] if root else []





def  _snake_case     (    UpperCAmelCase_  :					Node | None			):
     return postorder(root.left			) + postorder(root.right			) + [root.data] if root else []





def  _snake_case     (    UpperCAmelCase_  :					Node | None			):
     return [*inorder(root.left			), root.data, *inorder(root.right			)] if root else []





def  _snake_case     (    UpperCAmelCase_  :					Node | None			):
     return (max(height(root.left			)					,   height(root.right			)			) + 1) if root else 0





def  _snake_case     (    UpperCAmelCase_  :					Node | None			):
     A__										=  []

     if root is None:
          return output

     A__										=  deque([root]			)

     while process_queue:
          A__										=  process_queue.popleft()
          output.append(node.data			)

          if node.left:
               process_queue.append(node.left			)
          if node.right:
               process_queue.append(node.right			)
     return output





def  _snake_case     (    UpperCAmelCase_  :					Node | None					,   UpperCAmelCase_  :					int			):
     A__										=  []

     def populate_output(UpperCAmelCase_  :					Node | None					,   UpperCAmelCase_  :					int			) -> None:
          if not root:
               return
          if level == 1:
               output.append(root.data			)
          elif level > 1:
               populate_output(root.left					,   level - 1			)
               populate_output(root.right					,   level - 1			)

     populate_output(UpperCAmelCase_					,   UpperCAmelCase_			)
     return output





def  _snake_case     (    UpperCAmelCase_  :					Node | None					,   UpperCAmelCase_  :					int			):
     A__										=  []

     def populate_output(UpperCAmelCase_  :					Node | None					,   UpperCAmelCase_  :					int			) -> None:
          if root is None:
               return
          if level == 1:
               output.append(root.data			)
          elif level > 1:
               populate_output(root.right					,   level - 1			)
               populate_output(root.left					,   level - 1			)

     populate_output(UpperCAmelCase_					,   UpperCAmelCase_			)
     return output





def  _snake_case     (    UpperCAmelCase_  :					Node | None			):
     if root is None:
          return []

     A__										=  []

     A__										=  0
     A__										=  height(UpperCAmelCase_			)

     for h in range(1					,   height_tree + 1			):
          if not flag:
               output.append(get_nodes_from_left_to_right(UpperCAmelCase_					,   UpperCAmelCase_			)			)
               A__										=  1
          else:
               output.append(get_nodes_from_right_to_left(UpperCAmelCase_					,   UpperCAmelCase_			)			)
               A__										=  0

     return output





def  _snake_case     (    ):  # Main function for testing.
     A__										=  make_tree()
     print(F"""In-order Traversal: {inorder(UpperCAmelCase_			)}"""			)
     print(F"""Pre-order Traversal: {preorder(UpperCAmelCase_			)}"""			)
     print(F"""Post-order Traversal: {postorder(UpperCAmelCase_			)}"""					,   """\n"""			)

     print(F"""Height of Tree: {height(UpperCAmelCase_			)}"""					,   """\n"""			)

     print("""Complete Level Order Traversal: """			)
     print(level_order(UpperCAmelCase_			)					,   """\n"""			)

     print("""Level-wise order Traversal: """			)

     for level in range(1					,   height(UpperCAmelCase_			) + 1			):
          print(F"""Level {level}:"""					,   get_nodes_from_left_to_right(UpperCAmelCase_					,   level=UpperCAmelCase_			)			)

     print("""\nZigZag order Traversal: """			)
     print(zigzag(UpperCAmelCase_			)			)


if __name__ == "__main__":
 import doctest

 doctest.testmod()
 main()









"""simple docstring"""



def  _snake_case     (    UpperCAmelCase_  :					List[str]			):
     A__										=  [0] * len(UpperCAmelCase_			)
     A__										=  []
     A__										=  [1] * len(UpperCAmelCase_			)

     for values in graph.values():
          for i in values:
               indegree[i] += 1

     for i in range(len(UpperCAmelCase_			)			):
          if indegree[i] == 0:
               queue.append(UpperCAmelCase_			)

     while queue:
          A__										=  queue.pop(0			)
          for x in graph[vertex]:
               indegree[x] -= 1

               if long_dist[vertex] + 1 > long_dist[x]:
                    A__										=  long_dist[vertex] + 1

               if indegree[x] == 0:
                    queue.append(UpperCAmelCase_			)

     print(max(UpperCAmelCase_			)			)


# Adjacency list of Graph
SCREAMING_SNAKE_CASE_					:	Any							  =						{0: [2, 3, 4], 1: [2, 7], 2: [5], 3: [5, 7], 4: [7], 5: [6], 6: [7], 7: []}

longest_distance(graph)






