Given a connected graph G = (V, E), a Safe Set S is a subset of the vertex set V such that the cardinality of each connected component in the subgraph induced by V \ S does not exceed the cardinality of any neighbor connected component in the subgraph induced by S. When the vertices of G are weighted, the weight of a component is defined as the sum of the weights of its vertices, and the notion of safe set is extended by considering the weight of connected components in subgraphs induced by S and by V \ S. We propose an integer linear formulation which can tackle the four variants of the problem which arise by imposing connectivity of the safe set, and by considering weighted or unweighted vertices, respectively. Despite alternative formulations from the literature, that require a large number of variables, our formulation only uses one variable per vertex. The formulation has an exponential number of constraints, which are needed to define the structure of the safe set, and can be generated on-the-fly within a branch-and-cut algorithm. We describe linear-time separation procedures for these constraints, as well as families of additional inequalities based on cliques and on minimum weight cut separators, and discuss separation algorithms. A branch-and-cut algorithm that solves the proposed formulation is computationally compared with the state-of-the-art alternative formulation from the literature, and shows faster in solving most of benchmark instances.