All problems
Moralization Edges Added
Problem
Moralizing a directed acyclic graph connects every pair of parents that share a child unless they are already adjacent, then drops edge directions. Given edges as [parent, child] pairs, return the number of distinct undirected edges that moralization adds. Return 0 for malformed inputs.
Hint
Count each unmarried parent pair once, even when the parents share several children.
Test cases
case 1
in: [[[0,2],[1,2]]]
expected: 1
case 2
in: [[[0,2],[1,2],[0,1]]]
expected: 0
case 3
in: [[[0,2],[1,2],[3,2]]]
expected: 3
case 4
in: [[[0,3],[1,3],[0,4],[1,4]]]
expected: 1
case 5
in: [[[0,2,1]]]
expected: 0
Starter codePython
def moralization_edges_added(edges):
# Your code here
pass5 test cases · run your code against them in the editor