← 返回 rippling 的题目列表Task Scheduler with Parent-Child Dependencies
类型:online_judge
Problem: Task Scheduler with Parent-Child Dependencies
Based on the previous task scheduler, each task now has a parent_id. A task may be a child of another task.
Each task has:
id: unique task ID
parent_id: parent task ID; - means no parent
due_date: due date in YYYY-MM-DD format
create_time: ISO-style creation timestamp
is_high_priority: 1 for high priority, 0 otherwise
assignee: assignee name; - means unassigned
completed: 1 if completed, 0 otherwise
Return the running order of tasks.
Filtering rules are the same as before:
Exclude tasks that already have an assignee.
Exclude completed tasks.
Dependency and sorting rules:
Schedule only tasks that remain after filtering.
If a task's parent also remains after filtering, the parent must run before the child.
Once a parent runs, immediately run all runnable child subtrees of that parent.
A task with no runnable parent is treated as a root task.
Root tasks are sorted by (due_date ascending, is_high_priority descending, create_time ascending, id ascending).
Children of the same parent are sorted by the same rule.
The filtered parent-child graph is guaranteed to be acyclic.
Output rules:
Print one task id per line.
If no task should run, print EMPTY.
Input Format
The first line contains an integer n.
The next n lines are pipe-separated:
id|parent_id|due_date|create_time|is_high_priority|assignee|completed
Constraints
0 <= n <= 200000
id is unique
due_date and create_time can be compared lexicographically
The filtered dependency graph is a forest and contains no cycle
Example
Input:
5
A|-|2024-01-02|2024-01-01T09:00:00|0|-|0
B|A|2024-01-01|2024-01-01T08:00:00|1|-|0
C|-|2024-01-01|2024-01-01T10:00:00|0|-|0
D|B|2024-01-03|2024-01-01T11:00:00|0|-|0
E|-|2024-01-01|2024-01-01T07:00:00|1|alice|0
Output:
C
A
B
D
Explanation: E is filtered out because it has an assignee. The root tasks are A and C; C has the earlier due date, so it runs first. Then A runs, immediately followed by its child subtree B -> D.
Example
Input
5
A|-|2024-01-02|2024-01-01T09:00:00|0|-|0
B|A|2024-01-01|2024-01-01T08:00:00|1|-|0
C|-|2024-01-01|2024-01-01T10:00:00|0|-|0
D|B|2024-01-03|2024-01-01T11:00:00|0|-|0
E|-|2024-01-01|2024-01-01T07:00:00|1|alice|0
Output
C
A
B
D