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