/mcs algorithm for the minimum dyeing of chord graphs
Orz POPOQQQ (UPD:YDC's writing seems to be more familiar with some ... (similar to the heap optimization dij AH ~
Leave a hole first ... Take a look at it tomorrow ... It feels so amazing >_< (the perfect elimination sequence of the string diagram is like a topological sequence to the DAG, so many of the problems of the chord graph are done by this perfect elimination sequence)
1 /**************************************************************2 problem:10063 User:tunix4 language:c++5 result:accepted6 time:536 Ms7 memory:34996 KB8 ****************************************************************/9 Ten //Bzoj 1006 One#include <vector> A#include <cstdio> -#include <cstdlib> -#include <cstring> the#include <iostream> -#include <algorithm> - #defineRep (i,n) for (int i=0;i<n;++i) - #defineF (i,j,n) for (int i=j;i<=n;++i) + #defineD (i,j,n) for (int i=j;i>=n;--i) - using namespacestd; + A intGetint () { at intv=0, sign=1;CharCh=GetChar (); - while(ch<'0'|| Ch>'9') {if(ch=='-') sign=-1; Ch=GetChar ();} - while(ch>='0'&&ch<='9') {v=v*Ten+ch-'0'; Ch=GetChar ();} - returnv*Sign ; - } -typedefLong LongLL; in Const intn=100010, inf=~0u>>2; - /*******************tamplate********************/ to structlist{ + intTo,next; -}table[4004004]; the intHead[n],tot; * intN,m,ans,best,f[n],list[n],seq[n],color[n],mark[n]; $ BOOLV[n];Panax Notoginseng voidAddint*h,intXinty) { -table[++tot].to=y; thetable[tot].next=H[x]; +h[x]=tot; A } the voidMCS () { + inti,j; -F (I,1, n) Add (list,0, i); $D (J,n,1){ $ while(1){ - for(i=list[best];i;i=Table[i].next) { - if(!v[table[i].to]) Break; the Elselist[best]=Table[i].next; - }Wuyi if(i) { the intx=table[i].to; -v[x]=1; seq[j]=x; Wu for(i=head[x];i;i=table[i].next) - if(!V[table[i].to]) { Aboutf[table[i].to]++; $ Add (list,f[table[i].to],table[i].to); -best=Max (best,f[table[i].to]); - } - Break; A}Elsebest--; + } the } - } $ intMain () { the #ifndef Online_judge theFreopen ("Input.txt","R", stdin); the //freopen ("Output.txt", "w", stdout); the #endif -N=getint (); m=getint (); in intx, y; theF (I,1, M) { theX=getint (); y=getint (); About Add (head,x,y); the Add (head,y,x); the } the MCS (); +D (J,n,1){ - intx=seq[j],i; the for(intI=head[x];i;i=table[i].next)Bayimark[Color[table[i].to]]=J; the for(i=1; I<=n && mark[i]==j;i++); thecolor[x]=i; -ans=Max (ans,i); - } theprintf"%d\n", ans); the return 0; the}
View Code 1006: [HNOI2008] Magical Country Time limit:20 Sec Memory limit:162 MB
submit:2208 solved:989
[Submit] [Status] [Discuss] 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)
Source [Submit] [Status] [Discuss]
"Bzoj" "1006" "HNOI2008" Magical Kingdom