Handle invalid graphs in input