To create a resumable tree explorer, we can use a priority queue to store the nodes to be explored, sorted by their priority product. We can also use a configuration flag to determine whether to use ancestor priorities seen at the time of discovery or to update them when changed. Here's a Python implementation of the resumable tree explorer: ```python import heapq class Node: def __init__(self, value, priority, children=None): self.value = value self.priority = priority self.children = children if children is not None else [] def __lt__(self, other): return self.priority > other.priority class TreeExplorer: def __init__(self, root, use_ancestor_priorities_at_discovery=True): self.root = root self.use_ancestor_priorities_at_discovery = use_ancestor_priorities_at_discovery self.priority_queue = [(root.priority, root)] def explore(self): while self.priority_queue: priority, node = heapq.heappop(self.priority_queue) print(f"Exploring node {node.value} with priority {priority}") for child in node.children: if self.use_ancestor_priorities_at_discovery: child_priority = priority * child.priority else: child_priority = self.calculate_priority(child) heapq.heappush(self.priority_queue, (child_priority, child)) def calculate_priority(self, node): if node == self.root: return node.priority parent_priority = self.calculate_priority(node.parent) return parent_priority * node.priority def update_priority(self, node, new_priority): node.priority = new_priority if not self.use_ancestor_priorities_at_discovery: for idx, (priority, n) in enumerate(self.priority_queue): if n == node: self.priority_queue[idx] = (self.calculate_priority(node), node) heapq.heapify(self.priority_queue) break ``` Here's an example of how to use the `TreeExplorer` class: ```python # Create a tree root = Node("A", 1) b = Node("B", 2) c = Node("C", 3) d = Node("D", 4) e = Node("E", 5) f = Node("F", 6) root.children = [b, c] b.children = [d, e] c.children = [f] # Initialize the tree explorer explorer = TreeExplorer(root, use_ancestor_priorities_at_discovery=True) # Explore the tree explorer.explore() # Update the priority of a node explorer.update_priority(d, 10) # Resume exploration explorer.explore() ``` This implementation uses a priority queue to efficiently explore nodes in order of their priority product. The `update_priority` method allows updating the priority of a node during exploration, and the exploration will be resumed accordingly based on the configuration flag.