← 返回 perplexity 的题目列表Implement an OOP ToDo List with Task CRUD, Status, and Dependencies (Cascade Updates)
类型:online_judge
Problem: Implement an OOP ToDo List with Dependencies (Python)
Implement the required functionality in Python following the provided skeleton with three classes:
TaskStatus (Enum): represents task states
Task: task entity
ToDoList: task manager
The problem is split into 4 parts, each with its own test cases. You implement features incrementally.
Part 1: Basic CRUD
Implement basic task management (CRUD) in ToDoList:
Create a task
Read/query a task
Update a task
Delete a task
Notes:
A unique identifier (e.g., task_id) is required as dictated by the tests.
Edge-case behaviors (e.g., non-existent task operations) must match the test expectations.
Part 2: Task Dependencies and Cascading Status Updates
Add dependency tracking and cascade logic.
Maintain dependency relationships
Allow adding dependencies to a task.
You must track both directions:
parents/prerequisites
children/dependents
Cascade rules
When a task becomes SUCCEEDED:
check tasks that depend on it; if their prerequisites are satisfied, they may transition from BLOCKED to READY.
When a task becomes FAILED:
propagate the failure recursively down the dependency graph (e.g., DFS over dependents).
Performance consideration
There is a large test where naive DFS propagation may TLE.
Avoid repeated traversals (e.g., visited set, incremental counters, etc.).
Part 3 / Part 4
Not described in the shared content; omitted.
Example
Input
# Part 1 示例(伪输入)
create 1 "A"
get 1
update 1 status READY
delete 1
get 1
Output
Task(id=1, title="A", status=READY)
NOT_FOUND