#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; #define N 1200 #define M 3000000 int n,m,x,y,tot,clock,top,cnt,sum,ss; int head[N],dfn[N],low[N],belong[N],p[N][N],col[N],stack[N],q[N],ff[N]; struct edge{int v,nxt;}e[M]; void add(int x,int y){e[++tot].v=y; e[tot].nxt=head[x]; head[x]=tot;} void init(){ clock=top=cnt=0; tot=1; memset(head,0,sizeof head); memset(e,0,sizeof e); memset(dfn,0,sizeof dfn); memset(low,0,sizeof low); memset(p,0,sizeof p); memset(col,-1,sizeof col); memset(ff,0,sizeof ff); memset(belong,0,sizeof belong); } void solve(int i){ int tt=0,ww=1; q[1]=i; col[i]=1; bool flag=0; while (tt<ww){ int u=q[++tt],color=col[u]; for (int j=head[u];j;j=e[j].nxt){ int v=e[j].v; if (belong[v]!=belong[u]) continue; if (col[v]==color){flag=1; break;} else if (col[v]==-1){col[v]=1^color; q[++ww]=v;} } if (flag) break; } if (flag) for (int j=1;j<=n;j++) if (belong[j]==belong[i]) ff[j]=1; } void tarjan(int u,int fa){ dfn[u]=low[u]=++clock; stack[++top]=u; for (int i=head[u];i;i=e[i].nxt){ if (i==(fa^1)) continue; int v=e[i].v; if (!dfn[v]){ tarjan(v,i); low[u]=min(low[u],low[v]); if (low[v]>=dfn[u]){ cnt++; for (;stack[top+1]!=v;){belong[stack[top]]=cnt; top--;} belong[u]=cnt; memset(col,-1,sizeof col); solve(u); } } else low[u]=min(low[u],dfn[v]); } } int main(){ while (1){ scanf("%d%d",&n,&m); if (n==0 && m==0) break; init(); for (int i=1;i<=m;i++){scanf("%d%d",&x,&y); p[x][y]=p[y][x]=1;} for (int i=1;i<=n;i++) for (int j=i+1;j<=n;j++) if (!p[i][j]){add(i,j); add(j,i);} for (int i=1;i<=n;i++) if (!dfn[i]) tarjan(i,0); sum=0; for (int i=1;i<=n;i++) if (!ff[i] || !head[i]) sum++; printf("%d\n",sum); } return 0; }
|