Сyclic routes in the table


In a $n × m$ table, some cells are locked. How to determinate time whether it is possible to split the remaining cells into cyclic routes of length at least $3$? All unremoved cells must participate in exactly one route exactly once. And the beginning of each route must coincide with its end.