题目链接: 传送门

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. Expression Blend4经验分享:制作一个简单的图片按钮样式

    这次分享如何做一个简单的图片按钮经验 在我的个人Silverlight网页上,有个Iphone手机的效果,其中用到大量的图片按钮 http://raimon.6.gwidc.com/Iphone/de ...

  2. 【REST WCF】30分钟理论到实践

    先来点理论知识,来自 http://www.cnblogs.com/simonchen/articles/2220838.html 一.什么是Rest REST软件架构是由Roy Thomas Fie ...

  3. CI(CodeIgniter)框架入门教程——第二课 初始MVC

    本文转载自:http://www.softeng.cn/?p=53 今天的主要内容是,使用CodeIgniter框架完整的MVC内容来做一个简单的计算器,通过这个计算器,让大家能够体会到我在第一节课中 ...

  4. 在Go语言中使用JSON(去掉空字段)

    Encode 将一个对象编码成JSON数据,接受一个interface{}对象,返回[]byte和error: func Marshal(v interface{}) ([]byte, error) ...

  5. C# Task 用法

    C# Task 的用法 其实Task跟线程池ThreadPool的功能类似,不过写起来更为简单,直观.代码更简洁了,使用Task来进行操作.可以跟线程一样可以轻松的对执行的方法进行控制. 顺便提一下, ...

  6. Bete冲刺第四阶段

    Bete冲刺第四阶段 今日工作: web: 昨晚搞得很晚,帮队友搞定了git的问题,仓库顿时干净多了,同时已经基本完成了基础功能的接口 ios: 导入并使用了改善交互的第三方开源库,修正路径BUG 目 ...

  7. 【Quartz】Quartz的搭建、应用(单独使用Quartz)

    Quartz在Java构建的系统中,是十分常用的定时任务框架. 本文,记录.介绍Quartz的简单入门的单独搭建(此文入门学习Quartz为主,并非基于Spring托管形式). > 参考的优秀资 ...

  8. sublime package control 被墙的解决方法

    在host里面配置 50.116.34.243 sublime.wbond.net 好用的插件地址 http://www.thinkphp.cn/topic/37057.html

  9. 转 ext文件系统及块组

    一.文件系统概述 1. 引导块 前文中介绍过磁盘需要进行分区和格式化,才能创建文件系统并使用,那么一块已经被各式化了分区其结构是什么样的呢?分区是按照柱面来划分的,而柱面包含的是磁道,磁道上包含的是扇 ...

  10. JavaIO流文件的操作总结

    IO流的分类 1.根据数据的流向: 输入流:用来读数据,如从外界设备读数据到内存中: 输出流:用来写数据,如从内存输出数据到外界存储设备: 2.根据数据流的格式: 字节流:一般用于声音或者秃瓢等二进制 ...