"Minimum Staining" "Hnoi 2008" "Bzoj 1006" Magical Kingdom

Source: Internet
Author: User

1006: [HNOI2008] The Magical kingdom
Time Limit: 20 Sec  Memory Limit: 162 MBSubmit: 2446  Solved: 1101

Description

K Country is a country of keen triangles, even people's contacts only like the triangle principle. They think triangular relationship: AB Mutual understanding, BC Mutual Understanding, CA mutual understanding, is concise and efficient. In order to consolidate triangular relations, the K-State prohibits the existence of four-sided relations, five-sided relations and so on ... There is only n pairs of cognitive relationships between an: (A1A2) (A2A3) ... (AnA1), and there is no other understanding. For example, four-sided relationship refers to ABCD four people ab,bc,cd,da mutual understanding, and ac,bd do not know. When the national competition, in order to prevent the harm, the provision of any pair of mutual understanding of the person must not be in a team, the king knows, at least how many detachment.

Input

The first row of two integers n,m. 1<=n<=10000,1<=m<=1000000. Indicates that there are N individuals, M to the cognitive relationship. Next, enter a pair of friends on each line of M line

Output

Output an integer, at least how many teams can be divided

Sample Input

4 51 21 42 42 33 4

Sample Output

3

HINT

一种方案(1,3)(2)(4)

Exercises

Thesis question. See-->CDQ Chord chart and interval diagram

Code:

#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <algorithm>using namespace Std;#define N 10010#define M 1000100struct edge{intVNext;} edge[m<<1];intNm,s, num=0, Head[n],b[n],c[n],d[n],Q[m]; bool Vis[n]={0};intIn () {int x=0; Char Ch=getchar (); while(ch<' 0 '|| Ch>' 9 ') Ch=getchar (); while(ch>=' 0 '&& ch<=' 9 ')x=x*10+ch-' 0 ', Ch=getchar ();return x;} void Add (intUintV) {edge[++num].v=v; Edge[num].Next=head[u]; Head[u]=num;}intMain () {n=in (),m=in ();s=0; for(intI=1; i<=m; i++) {intU=in (), V=in ();    Add (U,v), add (V,u); } memset (Vis,0, sizeof (VIS)); memset (D,0, sizeof (d)); for(intI=n; I i--) {intk=0; for(intj=1; j<=n; J + +)if(!vis[j] && d[j]>=d[k]) k=j; Vis[k]=true;Q[i]=k; for(intJ=HEAD[K]; J J=EDGE[J].Next) d[edge[j].v]++; } for(intI=n; I>0; i--) {intk=Q[i]; for(intJ=HEAD[K]; J J=EDGE[J].Next) B[c[edge[j].v]]=i; for(intj=1; ; J + +)if(b[j]!=i) {c[k]=j;s=max (s, j); Break; }    }printf("%d\ n",s);return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"Minimum Staining" "Hnoi 2008" "Bzoj 1006" Magical Kingdom

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.