title: Remove cycles from connected graph by finding vertices and edges
body: <p><a href="https://i.stack.imgur.com/GLSYY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GLSYY.png" alt="enter image description here"></a></p>
  
  <p>How can I remove all cycles from a graph like this? All edge lengths are one, and all edges are either vertical or horizontal. The graph is connected. </p>
  
  <p>I want to compute the smallest number of edges that have to be removed in order for the graph to contain no cycles.</p>
  
  <p>It would be really helpful if you included sample code (preferably C++, C or Java). </p>
  
  <p>UPDATE: Apparently I have to find the number of vertices and edges. 
  The problem I have gives a set of instructions like (down, left, up, down, left, left, up, down). You start from (0, 0) in the coordinate plane and move one unit in the specified direction. This will create a graph. How would I get the number of vertices and edges from this set of instructions?</p>