题目链接: 传送门

Graph Construction

Time Limit: 3000MS     Memory Limit: 65536K

Description

Graph is a collection of edges E and vertices V. Graph has a wide variety of applications in computer. There are different ways to represent graph in computer. It can be represented by adjacency matrix or by adjacency list. There are some other ways to represent graph. One of them is to write the degrees (the numbers of edges that a vertex has) of each vertex. If there are n vertices then n integers can represent that graph. In this problem we are talking about simple graph which does not have same endpoints for more than one edge, and also does not have edges with the same endpoint. Any graph can be represented by n number of integers. But the reverse is not always true. If you are given n integers, you have to find out whether this n numbers can represent the degrees of n vertices of a graph

Input

Each line will start with the number n (≤ 10000). The next n integers will represent the degrees of n vertices of the graph. A ‘0’ input for n will indicate end of input which should not be processed.

Output

If the n integers can represent a graph then print ‘Possible’. Otherwise print ‘Not possible’. Output for each test case should be on separate line.

Sample Input

4 3 3 3 3 6 2 4 5 5 2 1 5 3 2 3 2 1 0

Sample Output

Possible
Not possible
Not possible
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

bool cmp(int x,int y)
{
    return x>y;
}

int main()
{
    int N;
    while (~scanf("%d",&N) && N)
    {
        int ans[10005] = {0};
        bool flag = true;
        for (int i = 0;i < N;i++)
        {
            scanf("%d",&ans[i]);
        }
        while (flag)
        {
            sort(ans,ans+N,cmp);
            int tmp = ans[0];
            if (tmp == 0)
            {
                break;
            }
            for (int i = 1;i <= tmp;i++)
            {
                ans[i]--;
                if (ans[i] < 0)
                {
                    flag = false;
                    break;
                }
            }
            ans[0] = 0;
            if (!flag)
            {
                break;
            }
        }
        if (!flag)
        {
            printf("Not possible\n");
        }
        else
        {
            printf("Possible\n");
        }
    }
    return 0;
}

UVa 10720 - Graph Construction(Havel-Hakimi定理)的更多相关文章

  1. UVA 10720 Graph Construction 贪心+优先队列

    题目链接: 题目 Graph Construction Time limit: 3.000 seconds 问题描述 Graph is a collection of edges E and vert ...

  2. UVa 10720 - Graph Construction

    题目大意:给n个整数, 分别代表图中n个顶点的度,判断是否能构成一张图. 看到这个题后,除了所有数之和应该为偶数之外,没有别的想法了,只好在网上搜解题报告了.然后了解了Havel-Hakimi定理.之 ...

  3. POJ1659 Frogs' Neighborhood(Havel–Hakimi定理)

    题意 题目链接 \(T\)组数据,给出\(n\)个点的度数,问是否可以构造出一个简单图 Sol Havel–Hakimi定理: 给定一串有限多个非负整数组成的序列,是否存在一个简单图使得其度数列恰为这 ...

  4. UVA10720 Graph Construction 度序列可图性

    Luogu传送门(UVA常年上不去) 题意:求一个度序列是否可变换为一个简单图.$\text{序列长度} \leq 10000$ 题目看起来很简单,但是还是有一些小细节需要注意首先一个简单的结论:一张 ...

  5. uva 193 Graph Coloring(图染色 dfs回溯)

    Description You are to write a program that tries to find an optimal coloring for a given graph. Col ...

  6. UVa 1515 - Pool construction(最小割)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  7. uva 10733 The Colored Cubes<polya定理>

    链接:http://uva.onlinejudge.org/external/107/10733.pdf 题意: N 种颜色可以涂成多少种立方体~ 思路: 使正六面体保持不变的运动群总共有: 1.不变 ...

  8. UVA 1515 Pool construction 最大流跑最小割

    Pool construction You are working for the International Company for Pool Construction, a constructio ...

  9. UVA 11609 - Anne's game cayley定理

    Lily: “Chantarelle was part of my exotic phase.”Buffy: “It’s nice. It’s a mushroom.”Lily: “It is? Tha ...

随机推荐

  1. SQL Server中的索引结构与疑惑

    说实话我从没有在实际项目中使用过索引,仅知道索引是一个相当重要的技术点,因此我也看了不少文章知道了索引的区别.分类.优缺点以及如何使用索引.但关于索引它最本质的是什么笔者一直没明白,本文是笔者带着这些 ...

  2. C#基础之泛型

    1.泛型的本质 泛型的好处不用多说,在.NET中我看到有很多技术都是以泛型为基础的,不过因为不懂泛型而只能对那些技术一脸茫然.泛型主要用于集合类,最主要的原因是它不需要装箱拆箱且类型安全,比如很常用的 ...

  3. SQL2005SP4补丁安装时错误: -2146233087 MSDTC 无法读取配置信息。。。错误代码1603的解决办法

    是在安装slq2005sp3和sp4补丁的时候碰到的问题. 起先是碰到的错误1603的问题,但网上搜索的1603的解决办法都试过了,google也用了,外文论坛也读了,依然没有能解决这个问题. 其实一 ...

  4. 学习Python的三种境界

    前言 王国维在<人间词话>中将读书分为了三种境界:"古今之成大事业.大学问者,必经过三种之境界:'昨夜西风凋碧树,独上高楼,望尽天涯路'.此第一境也.'衣带渐宽终不悔,为伊消得人 ...

  5. 前端Mvvm QC 设计解析

    QC 官网http://time-go.github.io/qc/ QC的具体用法.介绍和源码,大家可以去官网下载 从本节开始,我会和大家一起分享在这个框架设计中用到的技巧,希望这些技巧能个大家带来灵 ...

  6. Ubuntu backlight

    我们可以通过键盘来调节亮度,但是那样亮度无法微调,每次变亮变得太多. 在 /sys/class/backlight/nv_backlight 这个目录下,brightness 是最主要的.backli ...

  7. 【Magenta 项目初探】手把手教你用Tensorflow神经网络创造音乐

    原文链接:http://www.cnblogs.com/learn-to-rock/p/5677458.html 偶然在网上看到了一个让我很感兴趣的项目 Magenta,用Tensorflow让神经网 ...

  8. Kernel Methods - An conclusion

    Kernel Methods理论的几个要点: 隐藏的特征映射函数\(\Phi\) 核函数\(\kappa\): 条件: 对称, 正半定; 合法的每个kernel function都能找到对应的\(\P ...

  9. Entity Framework Code First (七)空间数据类型 Spatial Data Types

    声明:本文针对 EF5+, Visual Studio 2012+ 空间数据类型(Spatial Data Types)是在 EF5 中引入的,空间数据类型表现有两种: Geography (地理学上 ...

  10. poj1236 强连通缩点

    Network of Schools Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 15211   Accepted: 60 ...