HDU 2454 Degree Sequence of Graph G(Havel定理 推断一个简单图的存在)
主题链接: pid=2454">http://acm.hdu.edu.cn/showproblem.php?pid=2454
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?
of the degree sequence.
2
6 4 4 3 3 2 2
4 2 1 1 1
yes
no
题意:
给出一个图的每个点的度数,求是否能构成一个简单图。
PS:
Havel定理:http://baike.baidu.com/view/8698382.htm?
fr=aladdin
关于详细图的构造,我们能够简单地把奇数度的点配对,剩下的所有搞成自环。
代码例如以下:
#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定理 推断一个简单图的存在)的更多相关文章
- hdu 2454 Degree Sequence of Graph G (推断简单图)
///已知各点的度,推断是否为一个简单图 #include<stdio.h> #include<algorithm> #include<string.h> usin ...
- HDU 2454"Degree Sequence of Graph G"(度序列可图性判断)
传送门 参考资料: [1]:图论-度序列可图性判断(Havel-Hakimi定理) •题意 给你 n 个非负整数列,判断这个序列是否为可简单图化的: •知识支持 握手定理:在任何无向图中,所有顶点的度 ...
- HDU 2454 Degree Sequence of Graph G——可简单图化&&Heavel定理
题意 给你一个度序列,问能否构成一个简单图. 分析 对于可图化,只要满足度数之和是偶数,即满足握手定理. 对于可简单图化,就是Heavel定理了. Heavel定理:把度序列排成不增序,即 $deg[ ...
- hdu 2454 Degree Sequence of Graph G(可简单图化判定)
传送门 •Havel-Hakimi定理: 给定一个非负整数序列{d1,d2,...dn},若存在一个无向图使得图中各点的度与此序列一一对应,则称此序列可图化. 进一步,若图为简单图,则称此序列可简单图 ...
- Hdoj 2454.Degree Sequence of Graph G 题解
Problem Description Wang Haiyang is a strong and optimistic Chinese youngster. Although born and bro ...
- 【Havel 定理】Degree Sequence of Graph G
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=2454 [别人博客粘贴过来的] 博客地址:https://www.cnblogs.com/debug ...
- cdoj913-握手 【Havel定理】
http://acm.uestc.edu.cn/#/problem/show/913 握手 Time Limit: 2000/1000MS (Java/Others) Memory Limit ...
- 2013长沙 G Graph Reconstruction (Havel-Hakimi定理)
Graph Reconstruction Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge Let there ...
- HDU 1560 DNA sequence(DNA序列)
HDU 1560 DNA sequence(DNA序列) Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K ...
随机推荐
- HUST 1017(DLX)
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=65998#problem/A 题意:求01矩阵的精确覆盖. DLX学习资料:ht ...
- HDU3537-Daizhenyang's Coin(博弈SG-打表)
<span style="color: green; font-family: Arial; font-size: 12px; background-color: rgb(255, 2 ...
- Android Graphics专题(1)--- Canvas基础
作为Android Graphics专题的开篇.毫无疑问,我们将讨论Android UI技术的核心概念--Canvas. Canvas是Android UI框架的基础,在Android的控件体系中.全 ...
- C# 简化优化if/switch 表驱动法
表示这个很强大 字典加反射,搞定多window的switch public partial class MainWindow : Window { Dictionary<string, Type ...
- DIV 居中对齐
<div style="text-align:center;margin-right:auto;margin-left:auto">
- windows下cocos2dx3.0开发环境及Android编译环境搭建
cocos2dx更新到了3.x版本号,自己一直没有换,如今开发组要求统一换版本号,我就把搭建好开发环境的过程记录下来. 一.Windowns下开发环境搭建 1. 所需工具 1)coc ...
- 染色法判断是否是二分图 hdu2444
用染色法判断二分图是这样进行的,随便选择一个点, 1.把它染成黑色,然后将它相邻的点染成白色,然后入队列 2.出队列,与这个点相邻的点染成相反的颜色 根据二分图的特性,相同集合内的点颜色是相同的,即 ...
- 设置Windows 8.1屏幕自己主动旋转代码, Auto-rotate function code
程序代码实现启用或禁用Windows 8.1 Tablet的自己主动旋转功能 方法一:使用SetDisplayAutoRotationPreferences函数功能 #include <Wind ...
- 使用Intellij Idea生成可执行文件jar,开关exe文件步骤
确保其Java代码是没有问题的,在IDEA常执行的,然后.按以下步骤: 步骤一:打开File -> Project Structure -> Artifacts,例如以下图 步骤二:点击& ...
- 输出无名空数组---精android、IOS App应用服务程序开发
直接输出 [] 示例文件_samples/app/array_null.json在轻开平台的_samples/app/文件夹下 太Easy.无法写出很多其它的内容,大家还是自己试试吧! ! ! 相关资 ...