For a (molecular) graph, the first Zagreb index M 1 is equal to the sum of squares of the vertex degrees, and the second Zagreb index M 2 is equal to the sum of products of degrees of pairs of adjacent vertices. In this paper, we show that all connected graphs with n vertices and k cut edges, the maximum (resp. minimum) M 1 -and M 2 -value are obtained, respectively, and uniquely, at K k n (resp. P k n ), where K k n is a graph obtained by joining k independent vertices to one vertex of K n−k and P k n is a graph obtained by connecting a pendent path P k+1 to one vertex of C n−k .