Treewidth algorithm