Here is the adjacency matrix of a (undirected) tree .
A vertex of a tree is a leaf , iff there is only one edge connected to it.
What is the number of leaves in the given tree?
Input Format and Constraints
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
The solution is straightforward. We check the degree for each node.