版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Game_Acm/article/details/82350533
bool ok[maxn]; int color[maxn];
//ok表示点是否存在图中,color表示点的颜色
bool dfs( int u , int col )
{
color[u] = col;
for( int i=head[u] ; i!=-1 ; i=es[i].next )
{
int v = es[i].to;
if ( !ok[v] ) continue;
if ( color[v]!=-1 )
{
if ( color[v]==col ) return false;
continue;
}
if ( !dfs( v , !col ) ) return false;
}
return true;
}