Added graph constructor with input checks.