题目大意:
弦图的最小染色.
题解:
裸题.
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(int &x){
x=0;static char ch;bool flag = false;
while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
#define rg register int
#define rep(i,a,b) for(rg i=(a);i<=(b);++i)
#define per(i,a,b) for(rg i=(a);i>=(b);--i)
const int maxn = 10010;
const int maxm = 1000010;
struct Edge{
int to,next;
}G[maxm<<1];
int head[maxn],cnt;
void add(int u,int v){
G[++cnt].to = v;
G[cnt].next = head[u];
head[u] = cnt;
}
vector<int>ws[maxn];
int seq[maxn],pos[maxn],fla[maxn],col[maxn];
int lab[maxn];
int main(){
int n,m;read(n);read(m);
int u,v;
rep(i,1,m){
read(u);read(v);
add(u,v);add(v,u);
}
int nw = 0,ans = 0;
rep(i,1,n) ws[0].push_back(i);
per(i,n,1){
while(1){
u = ws[nw].back();
if(pos[u]) ws[nw].pop_back();
else break;
while(ws[nw].empty()) -- nw;
}
seq[i] = u;pos[u] = i;
for(int p = head[u];p;p=G[p].next){
fla[ col[ G[p].to ] ] = i;
++ lab[G[p].to];
nw = max(nw,lab[G[p].to]);
ws[lab[G[p].to]].push_back(G[p].to);
}
rep(j,1,n){
if(fla[j] != i){
col[u] = j;
ans = max(ans,j);
break;
}
}
}
printf("%d
",ans);
return 0;
}