"Bzoj 1006" [HNOI2008] The Magical kingdom

Source: Internet
Author: User

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 Input4 5
1 2
1 4
2 4
2 3
3 4Sample Output3HINT

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

Most trend algorithm ... What the hell is that? string coloring ... I admit that I still do not understand. Basically it means to mark a picture from the beginning of the big, at the same time for points connected to the mark Point du++, the next mark is unmarked Point du the largest point, so as to form a queue in order to dye the queue, each Dianran the smallest color is OK, I do not know why this is right ...
1#include <cstdio>2 intn,m,cnt,ans,u,v,x,t;3 inthead[10005],du[10005],q[10005],col[10005],hash[10005];4 BOOLvis[10005];5 structdata{intTo,next;} e[2000005];6 voidInsintUintv)7{e[++cnt].to=v;e[cnt].next=head[u];head[u]=CNT;}8 intMain () {9scanf"%d%d",&n,&m);Ten      for(intI=1; i<=m;i++){ Onescanf"%d%d",&u,&v); A ins (u,v); ins (v,u); -     } -du[0]=-1; the      for(inti=n;i>=1; i--){ -         intx=0; -          for(intj=1; j<=n;j++) -             if(!vis[j]&&du[j]>du[x]) x=J; +vis[x]=1; q[i]=x; -          for(intj=head[x];j;j=E[j].next) { +             intv=e[j].to; Adu[v]++; at         } -     } -      for(intI=n;i>0; i--){ -          for(intJ=head[q[i]];j;j=e[j].next) hash[col[e[j].to]]=i; -         intj=1; -          while(hash[j]==i) J + +; incol[q[i]]=J; -         if(J>ans) ans=J; to     } +printf"%d", ans); -}

"Bzoj 1006" [HNOI2008] The 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.