this formula is applicable when graph is complete connected graph means every nodes to connected to other nodes
n= number of nodes say 5
total number of spanning tree =n^(n-2) =5^3 =125 spanning trees.
if graph is not complete connected graph ,in that case use kirchaff theorem.(represent graph in adjacency matrix).