Tree edges are those edges which appear in the final DFS forest. For example in case of connected graph (i.e. resulting dfs forest containg only one tree), if we run DFS over it, edges belonging to the resulting DFS tree are called tree edges.

Let us assume the graph has x number of connected (or strongly connected in case of a directed graph) components. And assume 1st component has K_{1 }tree edges, 2nd component has K_{2 }tree edges and xth component has K_{x }tree edges.

Such that K_{1 }+ K_{2} + K_{3} + ........ + K_{x} = K ( = total)

Or in other way we can imagine like, the final DFS forest has x trees and those trees are having K_{1 }, K_{2 }, K_{3} , .... K_{x}_{ }edges respectively.

Now we know that a tree having K_{x }edges contains K_{x} + 1 nodes. Similarly a tree having K_{1} edges contains K_{1 }+ 1 nodes, etc. and so on.

So, Summation of nodes in each tree = n

$(K_1 + 1) + (K_2 + 1) + (K_3 + 1) + ................ + (K_x + 1) = n \\ \ \ \ \ => (K_1+K_2+K_3+......+K_x) + x = n \\ \ \ \ \ => x = n - K$