You are given a directed acyclic graph (DAG) that represents trigger dependencies between tasks.
Your job is to compute how many times each node is triggered.
edges
, where each edge is a pair
(u, v)
meaning there is an edge
u -> v
.
entry
node ID.
edges
are valid nodes.
Example:
A, B, C, D, E, F
A -> B
B -> C
B -> D
C -> D
D -> E
D -> F
E -> F
A
Trigger propagation:
A
is triggered once (given).
B
is triggered once (from
A
).
C
is triggered once (from
B
).
D
is triggered twice (once from
B
, once from
C
).
E
is triggered twice (both from
D
).
F
is triggered four times (twice from
D
, twice from
E
).
So the result is something equivalent to:
Implement a function in Python with a signature such as:
The function should:
entry
are handled.
You may assume there are no cycles in the input graph.