"bzoj1006" [HNOI2008] Magical Kingdom

Source: Internet
Author: User

1006: [HNOI2008] Magical Country Time limit:20 Sec Memory limit:162 MB
submit:3114 solved:1401
[Submit] [Status] [Discuss] Description

The Kingdom of K is a country of keen triangle, even people's intercourse also only like the triangle principle. They think triangular relationship: that 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. The so-called N-side relationship, refers to n personal a1a2
... There is only n pairs of cognitive relationships between an: (A1A2) (A2A3) ... (AnA1), without other cognitive relationships. For example, four-sided relationship refers to ABCD four persons ab,bc,c
D,da know each other, and ac,bd do not know each other. In order to prevent the disadvantage of the race, it is stipulated that any pair of mutual acquaintance shall not be in a team, the King knows,
At least how many teams can be divided.

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
Friends

Output

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

Sample Input4 5
1 2
1 4
2 4
2 3
3 4Sample Output3HINT

One scenario (1,3) (2) (4)

Exercises

Due to the constraints in the problem, the built diagram must be a chord graph, the answer is the minimum color scheme of the chord graph.

First, the MCS algorithm is used to find the perfect elimination sequence of the chord graph, then the smallest color can be dyed from the back to the next, recording the answer.

So why is it right to do so?

Proof: We assume that the use of T color, then t>= color number, t= <= color number, so t= color number.

Complexity of Time: O (m+n)

Reference: Chen Danqi--"chord and Interval map"

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cstdlib>5#include <cmath>6#include <ctime>7#include <algorithm>8 using namespacestd;9 structnode{intY,next;} e[1000010*2];Ten intn,m,len,ans,link[10010],label[10010],vis[10010],q[10010],check[10010],col[10010]; OneInlineintRead () A { -     intx=0, f=1;CharCh=GetChar (); -      while(!isdigit (CH)) {if(ch=='-') f=-1; Ch=GetChar ();} the      while(IsDigit (CH)) {x=x*Ten+ch-'0'; Ch=GetChar ();} -     returnx*F; - } - voidInsertintXxintyy) + { -e[++len].next=Link[xx]; +link[xx]=Len; Ae[len].y=yy; at } - voidMCS ()//Maximum potential algorithm for perfect elimination sequence - { -      for(inti=n;i;i--) -     { -         intnow=0; in          for(intj=1; j<=n;j++) -             if(Label[j]>=label[now]&&!vis[j]) now=J; tovis[now]=1; q[i]=Now ; +          for(intj=link[now];j;j=e[j].next) -label[e[j].y]++; the     } * } $ voidColor ()//DyeingPanax Notoginseng { -      for(inti=n;i;i--) the     { +         intnow=q[i],j; A          for(intJ=link[now];j;j=e[j].next) check[col[e[j].y]]=i; the          for(j=1;; J + +)if(check[j]!=i) Break; +col[now]=J; -         if(J>ans) ans=J; $     } $ } - intMain () - { theN=read (); m=read (); -      for(intI=1; i<=m;i++)Wuyi     { the         intX=read (), y=read (); - Insert (x, y); Insert (y,x); Wu     } - MCS (); About color (); $printf"%d\n", ans); -     return 0; -}

"bzoj1006" [HNOI2008] 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.