class Node:
    def __init__(self, val=None, children=None):
        self.val = val
        self.children = children

# Recursive
def maxDepth(root: 'Node') -> int:
    if not root:
        return 0

    def search_max(cur_root: 'Node', depth: int):
        if not cur_root.children:
            return depth

        return max([search_max(child, depth + 1) for child in cur_root.children])

    return search_max(root, 1)

# Iterative
# def maxDepth(root: 'Node') -> int:
#     if not root:
#         return 0
#
#     max_depth = 1
#     stack = [(root, max_depth)]
#     while stack:
#         cur_node, cur_depth = stack.pop()
#         max_depth = max(max_depth, cur_depth)
#         for child in cur_node.children:
#             stack.append((child, cur_depth + 1))
#
#     return max_depth