Back to problems

Count Trigger Events in Directed Acyclic Graph

Algorithm · Robinhood · Medium

Given a directed acyclic graph and a designated starting node, every activation of that starting node activates each of its direct children one time, with those activations continuing through the remaining graph. Determine how many times every node is activated. Use letters for nodes and arrows for directed edges. For instance, with M->N, N->P, N->Q, P->Q, Q->R, Q->S, R->S and entry node M, the counts are M:1, N:1, P:1, Q:2, R:2, S:4. Solve this using Python. Example Input:…

Checking your access…