Basically, it's this rosalind problem.
You're given a number of nodes and an adjacency list. My initial guess was that the answer was the number of connected components minus 1, since by joining every connected component you would have a connected graph, and since it's stated that there are no cycles, that would be a tree.
Why is this approach wrong? The real answer is just the number of nodes-1-number of edges, which I understand, but can't see how is this not equivalent to my answer.
Also, the sample dataset given bugs me. I see three connected components so I don't see why the answer is not 2. Bear in mind, i'm almost new to graph theory so i'm sorry if i'm missing something simple.