hdu 2454 Degree Sequence of Graph G (判斷簡單圖)

來源:互聯網
上載者:User

標籤:style   color   io   ar   for   sp   c   on   amp   

///已知各點的度,判斷是否為一個簡單圖#include<stdio.h>#include<algorithm>#include<string.h>using namespace std;int a[1010];bool cmp(int x,int y){    return x>y;}int main(){    int t,n,i,j;    scanf("%d",&t);    while(t--)    {        int flag=1;        scanf("%d",&n);        for (i=0; i<n; i++)            scanf("%d",&a[i]);        sort(a,a+n,cmp);        while (a[0] && a[n-1]>=0)        {            int i = 1;            while (a[0]--)            {                --a[i++];            }            ++a[0];            sort(a,a+n,cmp);        }        if(a[n-1]<0)            printf("no\n");        else            printf("yes\n");    }    return 0;}

1,Havel-Hakimi定理主要用來判定一個給定的序列是否是可圖的。

2,首先介紹一下度序列:若把圖 G 所有頂點的度數排成一個序列 S,則稱 S 為圖 G 的度序列。

3,一個非負整數組成的有限序列如果是某個無向圖的序列,則稱該序列是可圖的。

4,判定過程:(1)對當前數列排序,使其呈遞減,(2)從S【2】開始對其後S【1】個數字-1,(3)一直迴圈直到當前序列出現負數(即不是可圖的情況)或者當前序列全為0 (可圖)時退出。

5,舉例:序列S:7,7,4,3,3,3,2,1  刪除序列S的首項 7 ,對其後的7項每項減1,得到:6,3,2,2,2,1,0,繼續刪除序列的首項6,對其後的6項每項減1,得到:2,1,1,1,0,-1,到這一步出現了負數,因此該序列是不可圖的。

hdu 2454 Degree Sequence of Graph G (判斷簡單圖)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.