http://www.lydsy.com/JudgeOnline/problem.php?id=1006
MCS算法见cdq论文
//#define _TEST _TEST
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;
/************************************************
Code By willinglive Blog:http://willinglive.cf
************************************************/
#define rep(i,l,r) for(int i=(l),___t=(r);i<=___t;i++)
#define per(i,r,l) for(int i=(r),___t=(l);i>=___t;i--)
#define MS(arr,x) memset(arr,x,sizeof(arr))
#define LL long long
#define INE(i,u,e) for(int i=head[u];~i;i=e[i].next)
#define MP make_pair
inline const int read()
{int r=0,k=1;char c=getchar();for(;c<'0'||c>'9';c=getchar())if(c=='-')k=-1;
for(;c>='0'&&c<='9';c=getchar())r=r*10+c-'0';return k*r;}
/
int n,m;
struct edge{int v,next;}e[2000010];
int head[10010],k;
priority_queue<pair<int,int> >heap;
int ind[10010],pos[10010],id[10010];
/
inline void MAX(int &a,int b){if(a<b)a=b;}
void adde(int u,int v){e[k].v=v;e[k].next=head[u];head[u]=k++;}
void MCS()
{
rep(i,1,n) heap.push(MP(ind[i]=0,i));
for(int cnt=n;cnt>=1;)
{
int u=heap.top().second; heap.pop();
if(id[u]) continue;
pos[cnt]=u; id[u]=cnt--;
INE(i,u,e)
{
int v=e[i].v; if(id[v]) continue;
ind[v]++;
heap.push(MP(ind[v],v));
}
}
}
void Color(int u)
{
int *vis=ind;
INE(i,u,e)
{
int v=e[i].v; if(!id[v]) continue;
vis[id[v]]=u;
}
for(int i=1;;i++) if(vis[i]!=u){id[u]=i;break;}
}
int ClrGraph()
{
MS(id,0); MS(ind,0);
per(i,n,1) Color(pos[i]);
int ans=0;
rep(i,1,n) MAX(ans,id[i]);
return ans;
}
/
void input()
{
MS(head,-1);
n=read(); m=read();
rep(i,1,m)
{
int u=read(),v=read();
adde(u,v); adde(v,u);
}
}
void solve()
{
MCS();
cout<<ClrGraph()<<endl;
}
/
int main()
{
#ifndef _TEST
freopen("std.in","r",stdin); freopen("std.out","w",stdout);
#endif
input(),solve();
return 0;
}