Minimum number of operations to connect a graph

Правка en1, от typedeftemplate, 2019-09-25 04:02:29

Given a set of nodes numbered 1, 2, .. N, and a list of edges, we define an "operation" as removing an existing edge between two vertices and placing it between two other vertices. What is the minimum number of operations needed to connect the graph?

We are given the number of vertices and edges as input, and then we are given the list of edges.

For instance, if there are 2 vertices and 1 edge, and the one edge is (1, 2), then you don't need any operations since you're already done.

On the other hand, if there are 4 vertices and the edges are (1, 2), (1, 3), and (2, 3), then 4 isn't connected, but you can remove any edge and connect it to get 4 with just one operation. So the output is 1.

How can I solve this problem?

I am thinking about finding the number of connected components, and going from there, but I have not been able to make any progress. I am really bad at graph implementations though, and I would really appreciate some sort of help.

Теги #graph, #graph theory, #connected components

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский typedeftemplate 2019-09-25 04:02:29 1026 Initial revision (published)