Skip to content
DeepForgeby svx
All problems
EasyGraph Algorithmsgraph-143

Arborescence Count 2-Node

Problem

Count the spanning arborescences rooted at root in a directed graph with exactly two nodes.

An arborescence needs one directed path from the root to the other node, so simply count the edges that go from the root to the other node, including parallel edges. edges is a list of [u, v] pairs.

Hint

For two nodes the count is just the number of usable root-to-node edges.

Test cases

case 1
in: [[[0,1],[0,1]],0]
expected: 2
case 2
in: [[[1,0]],0]
expected: 0
case 3
in: [[[1,0]],1]
expected: 1
case 4
in: [[[0,1],[1,0]],1]
expected: 1
case 5
in: [[],0]
expected: 0
Starter codePython
def arborescence_count_2node(edges, root):
    # Your code here
    pass

5 test cases · run your code against them in the editor