A characterization of certain closed 3-manifolds