# Ultraviolet A 10720 Graph Construction

Source: Internet
Author: User

Uva_000020

This question is a bit greedy, that is, if a point has a lot of degrees, it should be prioritized and connected to more vertices.

I first estimated the qsort time and thought it was troublesome, but later the boss said that he had used qsort before, so I started to write qsort. It may be because the pruning is used properly or the number of data on the subject is small.

`#include<stdio.h>#include<string.h>#include<stdlib.h>int a[10010],n,N,sum;int cmp(const void *_p,const void *_q){int *p=(int *)_p;int *q=(int *)_q;return *p-*q;}int judge(){int i,j,k,t;    qsort(a,n,sizeof(a[0]),cmp);for(k=n-1;k>0;k--)if(a[k])        {for(i=k-1;i>=0;i--)if(a[i])                {                    a[i]--;                    a[k]--;                    sum-=2;if(!a[k])break;                }if(a[k])break;            qsort(a,k,sizeof(a[0]),cmp);        }if(sum==0)return 1;elsereturn 0;}int main(){int i,j,k,max;while(1)    {        scanf("%d",&N);if(N==0)break;        n=max=sum=0;for(i=0;i<N;i++)        {            scanf("%d",&a[n]);if(a[n])            {if(a[n]>max)                    max=a[n];                sum+=a[n];                n++;            }        }if(sum==0)        {            printf("Possible\n");continue;        }else if(max>=n||sum%2!=0)        {            printf("Not possible\n");continue;        }if(judge())            printf("Possible\n");else            printf("Not possible\n");    }return 0;    }`

Related Keywords:

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.