Skip to content
DeepForgeby svx
All problems
HardGraph Algorithmsgraph-222

Block-Cut Tree Size

Problem

Compute the size of the block-cut tree of an undirected graph with n nodes.

Run a DFS that tracks discovery and low-link values, pushing tree edges on a stack and popping a block whenever low[child] >= disc[parent]; nodes that start blocks are articulation points. Return [block_count, articulation_count, total_nodes] where total_nodes is blocks plus articulation points.

Hint

The block-cut tree alternates block nodes and articulation points.

Test cases

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

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