residual graph constructor implemented