← 返回 doordash 的题目列表Refund Workflow Engine on a DAG
类型:online_judge
Problem: Refund Workflow Engine on a DAG
When a DoorDash order times out, a refund workflow needs to run several steps, such as:
Validate refund eligibility.
Calculate refund amount.
Call the payment system to issue a refund.
Notify the user.
Write audit logs.
These steps have dependencies and form a directed acyclic graph. Implement a workflow engine that executes all steps according to dependencies.
For judging purposes, executing a step is simplified to outputting the nodes that can run in each parallel round.
You are given n steps and m dependency edges. Edge A B means step B can run only after step A completes.
Requirements:
Return the execution plan grouped by rounds.
Steps in the same round can run in parallel and should be printed in lexicographical order.
If the graph has a cycle, print INVALID.
Each step should execute only once; repeated API calls should be avoided through workflow-step idempotency keys.
Input Format
n m
step_1
...
step_n
from_1 to_1
...
from_m to_m
Output Format
If the graph is acyclic, print one line per parallel execution round, with step names separated by spaces.
If there is a cycle, print:
INVALID
Constraints
1 <= n <= 2 * 10^5
0 <= m <= 2 * 10^5
Step names are strings without spaces.
Example
Input
5 4
validate
calculate
refund
notify
audit
validate calculate
calculate refund
refund notify
refund audit
Output
validate
calculate
refund
audit notify