2014 Liaoning Province game Traveling

Source: Internet
Author: User

Question K: Traveling

Time Limit: 1 Sec memory limit: 128 MB
Submission: 13 solution: 4
[Submit] [Status] [Forum]

Description

SH likes traveling around the world. when he arrives at a city, he will ask the staff about the number of cities that connected with this city directly. after traveling around a mainland, SH will collate data and judge whether the data is correct.

A group of data is correct when it can constitute an undirected graph.

Input

There are multiple test cases. the first line of each test case is a positive integer N (1 <= N <= 10000) standing for the number of cities in a mainland. the second line has N positive integers a1, a2 ,..., an. ai stands for the number of cities that connected directly with the ith city. input will be ended by the end of file.

Output

If a group of data is correct, output "YES" in one line, otherwise, output "NO ".

Sample Input

8 7 7 4 3 3 3 2 1 10 5 4 3 3 2 2 1 1

Sample output

NO YES

Prompt

This question is not difficult, and the data scope is not big. You only need to simulate the process. For details, see the code.

#include
 
  #include
  
   #include
   
    #include#include
    
     using namespace std;const int MAX=10005;int f[MAX];int main(){    int n;    while(scanf("%d",&n)!=EOF)    {        for(int i=0;i
     
      0&&p
      
       0) { f[p-1]--; f[i]--; } } if(f[i]!=0) { cout<<"NO"<
       
        

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.