主题链接:

pid=2454">http://acm.hdu.edu.cn/showproblem.php?pid=2454

Problem Description
Wang Haiyang is a strong and optimistic Chinese youngster. Although born and brought up in the northern inland city Harbin, he has deep love and yearns for the boundless oceans. After graduation, he came to a coastal city and got a job in a marine transportation
company. There, he held a position as a navigator in a freighter and began his new life.



The cargo vessel, Wang Haiyang worked on, sails among 6 ports between which exist 9 routes. At the first sight of his navigation chart, the 6 ports and 9 routes on it reminded him of Graph Theory that he studied in class at university. In the way that Leonhard
Euler solved The Seven Bridges of Knoigsberg, Wang Haiyang regarded the navigation chart as a graph of Graph Theory. He considered the 6 ports as 6 nodes and 9 routes as 9 edges of the graph. The graph is illustrated as below.



 



According to Graph Theory, the number of edges related to a node is defined as Degree number of this node.



Wang Haiyang looked at the graph and thought, If arranged, the Degree numbers of all nodes of graph G can form such a sequence: 4, 4, 3,3,2,2, which is called the degree sequence of the graph. Of course, the degree sequence of any simple graph (according to
Graph Theory, a graph without any parallel edge or ring is a simple graph) is a non-negative integer sequence?



Wang Haiyang is a thoughtful person and tends to think deeply over any scientific problem that grabs his interest. So as usual, he also gave this problem further thought, As we know, any a simple graph always corresponds with a non-negative integer sequence.
But whether a non-negative integer sequence always corresponds with the degree sequence of a simple graph? That is, if given a non-negative integer sequence, are we sure that we can draw a simple graph according to it.?



Let's put forward such a definition: provided that a non-negative integer sequence is the degree sequence of a graph without any parallel edge or ring, that is, a simple graph, the sequence is draw-possible, otherwise, non-draw-possible. Now the problem faced
with Wang Haiyang is how to test whether a non-negative integer sequence is draw-possible or not. Since Wang Haiyang hasn't studied Algorithm Design course, it is difficult for him to solve such a problem. Can you help him?


 
Input
The first line of input contains an integer T, indicates the number of test cases. In each case, there are n+1 numbers; first is an integer n (n<1000), which indicates there are n integers in the sequence; then follow n integers, which indicate the numbers
of the degree sequence.


 
Output
For each case, the answer should be "yes"or "no" indicating this case is "draw-possible" or "non-draw-possible"


 
Sample Input
2
6 4 4 3 3 2 2
4 2 1 1 1
 
Sample Output
yes
no
 
Source

题意:

给出一个图的每个点的度数,求是否能构成一个简单图。

PS:

Havel定理:http://baike.baidu.com/view/8698382.htm?

fr=aladdin

给定一个非负整数序列{dn},若存在一个无向图使得图中各点的度与此序列一一相应,则称此序列可图化。进一步。若图为简单图,则称此序列可简单图化
可图化的判定:d1+d2+……dn=0(mod 2)。

关于详细图的构造,我们能够简单地把奇数度的点配对,剩下的所有搞成自环。

可简单图化的判定(Havel定理):把序列排成不增序,即d1>=d2>=……>=dn,则d可简单图化当且仅当d’={d2-1,d3-1。……d(d1+1)-1, d(d1+2)。d(d1+3),……dn}可简单图化。简单的说,把d排序后,找出度最大的点(设度为d1),把它与度次大的d1个点之间连边,然后这个点就能够无论了。一直继续这个过程。直到建出完整的图。或出现负度等明显不合理的情况。

代码例如以下:

#include<cstdio>
#include<algorithm>
using namespace std;
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
int t,n,i,j;
int a[1010];
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
int sum = 0;
for(i=0; i<n; i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
if(sum%2)
{
printf("no\n");
continue;
}
for(i=0; i<n; i++)
{
if(a[i]>=n)
break;
}
if(i<n)
{
printf("no\n");
continue;
}
int flag = 0;
for(i=0; i<n; i++)
{
int cnt=0;
sort(a,a+n,cmp);
for(j=1; j<n; j++)
{
if(cnt==a[0])
break;
a[j]--;
cnt++;
if(a[j] < 0)
{
flag = 1;
break;
}
}
if(flag)
break;
if(cnt==0)
break;
a[0]-=cnt;
}
for(i=0; i<n; i++)
{
//printf("%d ",a[i]);
if(a[i])
break;
}
//printf("\n");
if(i<n || flag)
printf("no\n");
else
printf("yes\n");
}
return 0;
} /*
4
4 3 2 1 1
*/

版权声明:本文博客原创文章,博客,未经同意,不得转载。

HDU 2454 Degree Sequence of Graph G(Havel定理 推断一个简单图的存在)的更多相关文章

  1. hdu 2454 Degree Sequence of Graph G (推断简单图)

    ///已知各点的度,推断是否为一个简单图 #include<stdio.h> #include<algorithm> #include<string.h> usin ...

  2. HDU 2454"Degree Sequence of Graph G"(度序列可图性判断)

    传送门 参考资料: [1]:图论-度序列可图性判断(Havel-Hakimi定理) •题意 给你 n 个非负整数列,判断这个序列是否为可简单图化的: •知识支持 握手定理:在任何无向图中,所有顶点的度 ...

  3. HDU 2454 Degree Sequence of Graph G——可简单图化&&Heavel定理

    题意 给你一个度序列,问能否构成一个简单图. 分析 对于可图化,只要满足度数之和是偶数,即满足握手定理. 对于可简单图化,就是Heavel定理了. Heavel定理:把度序列排成不增序,即 $deg[ ...

  4. hdu 2454 Degree Sequence of Graph G(可简单图化判定)

    传送门 •Havel-Hakimi定理: 给定一个非负整数序列{d1,d2,...dn},若存在一个无向图使得图中各点的度与此序列一一对应,则称此序列可图化. 进一步,若图为简单图,则称此序列可简单图 ...

  5. Hdoj 2454.Degree Sequence of Graph G 题解

    Problem Description Wang Haiyang is a strong and optimistic Chinese youngster. Although born and bro ...

  6. 【Havel 定理】Degree Sequence of Graph G

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=2454 [别人博客粘贴过来的] 博客地址:https://www.cnblogs.com/debug ...

  7. cdoj913-握手 【Havel定理】

    http://acm.uestc.edu.cn/#/problem/show/913 握手 Time Limit: 2000/1000MS (Java/Others)     Memory Limit ...

  8. 2013长沙 G Graph Reconstruction (Havel-Hakimi定理)

    Graph Reconstruction Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge Let there ...

  9. HDU 1560 DNA sequence(DNA序列)

    HDU 1560 DNA sequence(DNA序列) Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K  ...

随机推荐

  1. Hdu 3410 【单调队列】.cpp

    题意: 给出一个数组,问你对于第i个数,从最后一个比它大的数到它之间比它小的数中最大的那个数的下标,以及它右边到第一个比它大的数中比它小的数中最大的那一个数的下标<下标从1开始>. eg: ...

  2. Knockout应用开发指南 第七章:Mapping插件

    原文:Knockout应用开发指南 第七章:Mapping插件 Mapping插件 Knockout设计成允许你使用任何JavaScript对象作为view model.必须view model的一些 ...

  3. PDF数据防扩散系统方案

    在企业信息化过程中.大量的企业重要图纸和资料都是以电子文件的方式存在.为了避免内部关键数据的外泄,採取了多种方式:设计部门的门禁管制.防火墙.禁止计算机的USB接口等等. 可是泄密问题还是时有发生,原 ...

  4. Revit 2015 公布!

    Revit 2015 公布了, 如今能够下载.大家能够搜索下中文版的下载. 之前就知道2015 的模型操作速度再次提高, 2015安装后的马上载入跑了一个模型.果然,2015 打开自带的高级模型,不管 ...

  5. 如何实现MySQL随机查询数据与MySQL随机更新数据?

    以下的文章主要介绍的是MySQL随机选取数据,对实现MySQ随机查询数据与MySQ随机更新数据的实际操作步骤的描述,以及对其实际操作中所要用到的语句的描述,以下就是对其具体操作步骤的描述. MySQL ...

  6. Redhat 6.3中syslog信息丢失

    我们採用Linux的syslog来记录产品的debug log. 调用当中的一个可运行文件.运行完命令之后,查看debug log的信息,竟然从某一条log之后的log都丢失了.多次尝试后,发现每次都 ...

  7. Libevent API

    evtimer_new evtimer_new(base, callback, NULL) 用来做定时器,即当达到一定时间后调用回调函数callback.用evtimer_add激活定时器.比如: m ...

  8. 用C设计,用C++编码

          昨天晚上看到刘江的blog又补充了好几大段,今天早上又看到云风的人肉trackback,果然还是这种话题引人关注. 云风先是提了一下所谓C++带来的思想包袱(文言文曰“心智包袱”)问题,然 ...

  9. FusionCharts简单教程---建立第一个FusionCharts图形

    由于项目需求需要做一个报表,选择FusionCharts作为工具使用.由于以前没有接触过报表,网上也没有比较详细的fusionCharts教程,所以决定好好研究FusionCharts,同时做一个比较 ...

  10. 0x00000000该内存不能为read

    0X000000存储器不能read解决方案 有这种现象方面,首先,在硬件,这有问题的内存,二,软件,其中有许多问题. 一:先说说硬件: 一般来说,电脑硬件不easy生病.内存故障的可能性并不大(非你的 ...