Forest X41530


Statement
 

pdf   zip

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

Input consists of several graphs. Every graph starts with its number of vertices nn and its number of edges mm, followed by mm pairs xx yy indicating an edge between vertices xx and yy. Assume 1n1041 \le n \le 10^4, 0m<n0 \le m < n, that vertices are numbered from 00 to n1n-1, and that there are neither repeated edges nor edges of the type xx xx.

Output

For every graph, if it is a forest print the number of trees it has. Otherwise, print “no”.

Public test cases
  • Input

    1 0
    2 1  1 0
    2 0
    4 3  0 1  1 2  0 2
    8 6  0 4  5 3  3 1  3 7  2 4  6 0
    8 6  0 1  2 1  3 4  4 5  5 3  7 6
    10 9  0 1  0 2  1 3  1 4  2 5  2 6  3 7  3 8  3 9
    

    Output

    1
    1
    2
    no
    2
    no
    1
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Albert Atserias
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    Unknown.
    User solutions
    C++