79645942

Date: 2025-05-30 18:41:10
Score: 1
Natty:
Report link

I was able to achieve a pruned DAG by following method.

Step 1: Obtain a topological ordering of the nodes in the DAG.

The Step 1 will give you the node number for a node id.

Step 2: Make an edge list with the node_id replaced with it's number obtained in step 1. The list will have each element of the form (src, dst).

Step 3: Sort the edge list by ascending order of the dst and if the dst is equal descending order of src.

Step 4: Iterate through the edge list and form a Graph. If the src and dst are in the Graph and there is a path from src to dst skip the edge, else add the edge to the Graph.

You will get a pruned graph.

I was able to get a pruned graph for my case, let me know if there is any edge case that invalidates the above method.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (1):
Posted by: Arun Kennedy