Design and implement a Node class for a mutable rooted tree. Requirements: store value, parent, and ordered children; support add_child, remove, move_subtree, and replace_child in O(
-
to O(k) time where k is affected children; provide DFS and BFS iterators; compute depth, subtree size, and path-to-root with efficient updates (e.g., maintain cached sizes and invalidate/update on mutations); serialize/deserialize to and from a nested list or JSON representation; and ensure the API is safe against creating cycles. Provide method signatures, complexity analysis, and tests demonstrating the operations.