最基础的二分图染色,水题不解释了
#include<stdio.h>
#include<string.h>
#define maxn 200
int color[maxn],vis[maxn];
int f[maxn][maxn];
int n,m,mark;
void clear()
{
memset(color,0,sizeof(color));
memset(f,0,sizeof(f));
memset(vis,0,sizeof(vis));
mark=color[0]=1;
}
void dfs(int u)
{
for(int i=0;i<n;i++)
if(f[u][i])
{
if(!vis[i])
{
color[i]=-color[u];
vis[i]=1;
dfs(i);
}
else if(color[i]==color[u])
{
mark=0;
return;
}
}
}
int main()
{
while(~scanf("%d%d",&n,&m))
{
int i,u,v;
clear();
for(i=0;i<m;i++)
{
scanf("%d%d",&u,&v);
f[u][v]=f[v][u]=1;
}
dfs(0);
if(mark)
printf("BICOLORABLE.\n");
else
printf("NOT BICOLORABLE.\n");
}
}