← 返回 perplexity 的题目列表Implement ToDo List for AI
类型:online_judge
Implement a ToDo list for AI with the following requirements:
Class Definitions:
TaskStatus (Enum): An enum class defining possible states of a task, such as READY, BLOCKED, SUCCEEDED, FAILED.
Task: The class representing a single task, including task id, status, along with tracking its dependencies and children.
ToDoList: The list containing all tasks.
Function Implementations:
add(task): Add a task. If dependencies are not completed, mark the task as BLOCKED.
get(task_id): Retrieve specific task information.
update_status(task_id, new_status): Update the status of a task. If a task becomes SUCCEEDED, change all its dependencies' status to READY; if it becomes FAILED, update all tasks depending on it to FAILED.
Note: Each function should ensure no regression on previous task behaviors with every update.
Example Input/Output:
Task dependencies: A -> B -> C
Status Updates:
update_status(A, SUCCEEDED) // B status becomes READY
add_task(C, [B]) // C initial status is BLOCKED
Example
Input
A,SUCCEEDED;B,A;C,B