Design and implement code to build a user action tree from application logs.
Implement build_action_trees(logs). Each log is a dictionary with id, user_id, action, parent_id, and timestamp. parent_id is None for a root action. Return a dictionary mapping each user ID to a list of root nodes, where each node has id, action, and children. Logs may be unordered; roots and children must be ordered by (timestamp, id). Every non-root parent exists for the same user, and action IDs are globally unique.
Input: logs, a list of dictionaries. Output: a dictionary of nested action trees.
def build_action_trees(logs):