SPOJ: PT07Y – Is it a tree

PT07Y – Is it a tree

#dfs

 

You are given an unweighted, undirected graph. Write a program to check if it’s a tree topology.

Input

The first line of the input file contains two integers N and M — number of nodes and number of edges in the graph (0 < N <= 10000, 0 <= M <= 20000). Next M lines contain M edges of that graph — Each line contains a pair (u, v) means there is an edge between node u and node v (1 <= u,v <= N).

Output

Print YES if the given graph is a tree, otherwise print NO.

Example

Input:
3 2
1 2
2 3
Output:
YES

Solution


problem source – http://www.spoj.com/problems/PT07Y/

3 responses to “SPOJ: PT07Y – Is it a tree

  1. Gгeat post. I was ϲһecҝing constantly this blog and
    I am impressed! Extremely uѕeful info particularly
    the last paгt 🙂 I care for sᥙch info a lot. I was seeking
    this рarticulaг infо for a very long time.

    Thank you and good ⅼuck.

  2. Thanks for the ideas you have shared here. Something important I would like to talk about is that computer system memory needs generally rise along with other breakthroughs in the engineering. For instance, when new generations of processors are brought to the market, there is usually a related increase in the shape calls for of both the personal computer memory and also hard drive space. This is because the program operated by these processor chips will inevitably increase in power to make new technology.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Bitnami