A forest is a graph without cycles, and each of its connected components is a tree. Given an undirected graph, is it a forest? In case it is, how many trees does it have?
Input consists of several graphs. Every graph starts with its number of vertices and its number of edges , followed by pairs indicating an edge between vertices and . Assume , , that vertices are numbered from to , and that there are neither repeated edges nor edges of the type .
For every graph, if it is a forest print the number of trees it has.
Otherwise, print “no”.
Author: Unknown
Translator: Albert Atserias
Generation: 2026-01-25T15:59:58.687Z
© Jutge.org, 2006–2026.
https://jutge.org