Skip to main content
Admissions guidance, study banks, and career tools — get started on Shalyam

All Ancestors of a Node in a DAG

For every node of a directed acyclic graph print all of its ancestors (nodes that can reach it), in ascending order, one node per line. Print an empty line for a node with no ancestors.

Constraints

1 <= n <= 1000 0 <= m <= 2000

Discussion

No discussions yet.

Rewards · v2.1

Get Exclusive Insights with Every Issue

Join Shalyam Newsletter

Stay ahead in education, research, and innovation—straight to your inbox.