Skip to content
DeepForgeby svx
All problems
MediumGraph Algorithmsgraph-314

K4 Minor Check

Problem

Decide whether an undirected graph has a K4 minor, which is equivalent to treewidth at least 3.

Enumerate all assignments of the n vertices to four non-empty blocks, keep the assignments where every block is connected and every pair of blocks has an edge between them, and return True if any assignment survives. edges is a list of [u, v] pairs and n is small. Graphs with fewer than four vertices return False.

Hint

Each block of a minor model must be connected and adjacent to every other block.

Test cases

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

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