Bzoj 1006: [HNOI2008] Magical country--chord graph (Maximum potential algorithm)

Source: Internet
Author: User

1006: [HNOI2008] Magical Country Time limit:20 Sec Memory limit:162 MB 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)

Source

What's the string chart or watch the CDQ winter Camp courseware?

Then the problem is that the maximum potential algorithm to engage in, with the chain list words time complexity of the best O (n+m)//But I was too weak spicy, and did not write it out.

#include <map>#include<cmath>#include<queue>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespacestd;#defineINF 1000000007#definell Long Long#defineM 2000010#defineN 10010inlineintRd () {intx=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}intLj[n],fro[m],to[m],cnt;inlinevoidAddintAintb) {fro[++cnt]=lj[a];to[cnt]=b;lj[a]=CNT;}intNum[n],ji[n],col[n],hs[n];p riority_queue<pair<int,int> >Q;#defineMP Make_pairintn,m,p[n],mx;BOOLVs[n];intMain () {n=rd (); m=Rd ();  for(intI=1, x,y;i<=m;i++) {x=rd (); y=Rd ();    Add (x, y); add (y,x); } for(intI=1; i<=n;i++) Q.push (MP (0, i));  for(inti=n,x;i;i--)    {         while(Vs[q.top (). Second]) Q.pop (); X=q.top (). Second;q.pop (); VS[X]=1; num[i]=x;  for(intj=lj[x];j;j=Fro[j])if(!vs[to[j]]) Q.push (MP (+ +)ji[to[j]],to[j])); }     for(inti=n,x;i;i--) {x=Num[i];  for(intj=lj[x];j;j=Fro[j])if(Col[to[j]]) hs[col[to[j]]]=i;  for(intj=1; j<=mx;j++)if(hs[j]!=i) {col[x]=j; Break;} if(!col[x]) col[x]=++MX; } printf ("%d\n", MX); return 0;}

Bzoj 1006: [HNOI2008] Magical country--chord graph (Maximum potential algorithm)

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.