HDU 2454 degree sequence of graph G (judge a simple graph)

Source: Internet
Author: User

/// Determine whether the degree of each point is a simple graph # 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. the Havel-Hakimi theorem is mainly used to determine whether a given sequence is linear.

2. First, we will introduce the degree sequence: If the degrees of all vertices in graph G are arranged in a sequence S, S is called the degree sequence of graph G.

3. If a finite sequence composed of non-negative integers is an undirected graph sequence, it is called a sequence.

4. determination process: (1) sort the current sequence in descending order, and (2) sort the subsequent s numbers-1 from S [2, (3) keep repeating until the current sequence shows a negative number (that is, if it is not a sequence) or the current sequence is all 0 (sequence) and exits.

5. For example, sequence S: 7, 7, 4, 3, 3, deletes the first item 7 of sequence S, minus 1 for each of the following seven items, and obtains: 6, 3, 2, 2, 1, 0. Continue to delete the first item 6 of the sequence, and subtract 1 from each item of the next six items to get:, 0,-1. A negative number occurs at this step, therefore, this sequence cannot be illustrated.

HDU 2454 degree sequence of graph G (judge a simple graph)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.