[Problem]Coffee treat with crush

I recently learnt about Graphs and  very excited!

I went over to the Graph-making factory to watch some freshly prepared graphs. Incidentally, I have seen  beautiful girl who is making nice graphs.
so I decided to step in and invite her for a coffee.
But she gave me one of her problem and said if I solve that she will come with me for a coffee :-(.
My Job is to Identify whether the incoming graph is a tree or not. I was given given N, the number of vertices in the graph and the degree of each vertex.

Find if the graph is a tree or not.

Input:
First line contains an integer N, the number of vertices.
Second line contains N space-separated integers, the degrees of the N vertices.

Output:
Print "Yes" (without the quotes) if the graph is a tree or "No" (without the quotes) otherwise.

Constraints:
1 ≤ N ≤ 100
1 ≤ Degree ≤ 1000



Note:
 For any graph sum of degree of all vertices = 2 * (number of edges.
 Because each edge contributes a degree of 1 to the 2 vertices it connects.So     adding an edge increases sum of degrees by 2.



Source: https://www.hackerearth.com

No comments:

Post a Comment