Fix stop condition in depth first traversal

Also generate graphs for CPM1 and CPM2 test cases