图上的最小的染色方案;
学习了陈丹绮的论文: MCS算法
#include<cstdio> #define maxn 10005 #define maxm 2000005 using namespace std; int head[maxn],next[maxm],edge[maxm]; int cnt; int d[maxn],f[maxn]; void add(int a,int b) { edge[++cnt]=b; next[cnt]=head[a]; head[a]=cnt; } int main() { int n,m,x,y; scanf("%d%d",&n,&m); while(m--) { scanf("%d%d",&x,&y); add(x,y); add(y,x); } d[0]=-1; int ans=0; for(int i=n; i>0; i--) { int k=0; for(int j=1;j<=n;j++) if(!f[j]&&d[j]>d[k])k=j;//chose the k with the max label; f[k]=i; for(int j=head[k];j;j=next[j]) if(!f[edge[j]]) ++d[edge[j]];//add one in label for adject vertex of k; } for(int i=1;i<=n;i++) if(d[i]>ans)ans=d[i]; printf("%d ",ans+1); return 0; }