Monk at the Graph Factory
Practice
3.6 (254 votes)
Approved
Easy
Graphs
Open
Trees
Problem
91% Success 26886 Attempts 20 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Our Code Monk recently learnt about Graphs and is very excited!

He went over to the Graph-making factory to watch some freshly prepared graphs. Incidentally, one of the workers at the factory was ill today, so Monk decided to step in and do her job.

The Monk's Job is to Identify whether the incoming graph is a tree or not. He is 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 ≤ Degreei ≤ 1000

References:
Graphs and Trees

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
3 votes
Tags:
GraphsReal worldGraph RepresentationData StructuresAlgorithms
Points:20
34 votes
Tags:
AlgorithmsEasyGraphs
Points:20
78 votes
Tags:
AlgorithmsGraphs