標籤: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 (判斷簡單圖)