Jointly Learning Cost and Constraints from Demonstrations for Safe Trajectory Generation