"Parse" perfect elimination sequence + staining
[Analysis]
By knowing their relationship constitutes a chord graph, it is certain that the perfect elimination sequence must be established.
The first is to find out, then according to the sequence to dye, as small as possible.
In fact, the time stamp there with a line tree + two points seems to be good, even the tree array can be, because the changes in the element is monotonous ...
Here is the proof:
First, the following definitions are made:
Number of groups: the size of the largest regiment.
Chromatic number: The color that is least used for dyeing.
The colors in the ∵ group are 22 different.
∴ <= Chromatic number of the group
∵ we dye the color of the series and this stain is legal, but it is not guaranteed at least for the time being.
∴t>= color number.
and ∵ our staining method is greedy, encountering the last element of the regiment dyeing the most
∴t= of the regiment.
∴ number >= color number, regiment number <= color number
∴ = number of colors.
Number of ∴t= = number of colors, certificate of completion.
PPT in the implementation of O (N+m) is not clear, Poke here can see the implementation of MCS: http://tieba.baidu.com/p/2891159900.
[Sum]
The number of ① of the chord graph = number of colors.
② three ways to perfect the elimination sequence: violence, priority queuing, linearity.
③ If you want to change the elements in the queue, it is equivalent to re-inserting the elements so that the elements in the original queue do not have an effect.
Used in a variety of data structures such as priority queues, linked lists, and more.
④ the method of recording time stamp staining.
[Code] Priority queue
problem:1006 user:y20070316 language:c++ Res ult:accepted time:848 Ms memory:28960 kb****************************************************************/#include <cstdio> #include <cstring> #include <cstdlib> #include <queue>using namespace std; const int N=10001;const int m=1000001; struct g{int v,nxt;} Map[m+m];int Tt,hd[n]; Graphint lab[n],tid[n],seq[n];int color[n],r[n],colornum;int n,m;struct node{int w,id; friend bool operator< (node A,node b) {return a.w<b.w; }};p riority_queue<node> q; inline int read (void) {int s=0,f=1; char C=getchar (); for (;c< ' 0 ' | | C> ' 9 '; C=getchar ()); for (; ' 0 ' <=c&&c<= ' 9 '; C=getchar ()) s=s*10+c-48; return s*f;} inline void ins (int u,int v) {map[++tt].v=v; Map[tt].nxt=hd[u]; Hd[u]=tt;} void Init_graph (void) {int x, y; N=read (), M=read (); for (int i=1;i<=m;i++) { X=read (), Y=read (); Ins (x, Y), ins (y,x); }} void Get_queue (void) {node t; for (int i=1;i<=n;i++) {t.id=i,t.w=lab[i]; Q.push (t); } for (int num=n;num>0;num--) {for (;! Q.empty ();) {t=q.top (), Q.pop (); if (!tid[t.id]) break; } Seq[num]=t.id,tid[t.id]=num; for (int k=hd[t.id];k;k=map[k].nxt) if (!tid[map[k].v]) {lab[map[k].v]++; T.ID=MAP[K].V; T.W=LAB[MAP[K].V]; Q.push (t); }}} void Color_graph (void) {int now; for (int num=n;num>0;num--) {Now=seq[num]; for (int k=hd[now];k;k=map[k].nxt) if (tid[map[k].v]>num) R[color[map[k].v]]=now; int d=0; for (int k=1;k<=colornum;k++) if (r[k]^now) {color[now]=k; d=1; Break } if (!d) color[now]=++colornum; } printf ("%d\n", colornum);} int main (void) {init_graph (); Get_queue (); Color_graph (); return 0;} </span>
[Code] list
<span style= "FONT-SIZE:18PX;" >/************************************************************** problem:1006 user:y20070316 language:c++ result:accepted time:484 Ms memory:24596 kb****************************************************************/#inc Lude <cstdio> #include <cstring> #include <cstdlib> #include <queue>using namespace std; const int N=10001;const int m=1000001; struct g{int v,nxt;} Map[m+m];int Tt,hd[n]; Graphint lab[n],tid[n],seq[n];int Color[n],r[n],colornum;int n,m; G List[n+m]; int mxf,lhd[n],tl; List for MCS inline int read (void) {int s=0,f=1; char C=getchar (); for (;c< ' 0 ' | | C> ' 9 '; C=getchar ()); for (; ' 0 ' <=c&&c<= ' 9 '; C=getchar ()) s=s*10+c-48; return s*f;} inline void insg (int u,int v) {map[++tt].v=v; Map[tt].nxt=hd[u]; Hd[u]=tt;} void Init_graph (void) {int x, y; N=read (), M=read (); for (int i=1;i<=m;i++) {x=read (), Y=read (); INSG (x, y), INSG (y,x);}} inline void inslist (int floor,int id) {list[++tl].v=id; List[tl].nxt=lhd[floor]; LHD[FLOOR]=TL;} void Get_queue (void) {int now; for (int i=1;i<=n;i++) inslist (lab[i],i); for (int. num=n;num>0;num--) {for (; TID[LIST[LHD[MXF]].V];) {lhd[mxf]=list[lhd[mxf]].nxt; if (!LHD[MXF]) mxf--; } now=list[lhd[mxf]].v; LHD[MXF]=LIST[LHD[MXF]].NXT; for (;! LHD[MXF];) mxf--; Tid[now]=num,seq[num]=now; for (int k=hd[now];k;k=map[k].nxt) if (!tid[map[k].v]) {lab[map[k].v]++; if (LAB[MAP[K].V]>MXF) MXF=LAB[MAP[K].V]; Inslist (LAB[MAP[K].V],MAP[K].V); }}} void Color_graph (void) {int now; for (int num=n;num>0;num--) {Now=seq[num]; for (int k=hd[now];k;k=map[k].nxt) if (tid[map[k].v]>num) R[color[map[k].v]]=now; int d=0; for (int k=1;k<=colornum;k++) if (r[k]^now) {color[now]=k; d=1; Break } if (!d) color[now]=++colornum; } printf ("%d\n", Colornum);} int main (void) {init_graph (); Get_queue (); Color_graph (); return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"Bzoj" 1006 Magical Kingdom