Skip to content

染色法判断二分图 ​

  • 不含奇数环等价于染色法过程不存在矛盾
cpp
bool dfs(int u,int c){
    col[u]=c;
    for(auto v:adj[u]){
        if(col[v]){
            if(col[v]==c)return false;
        }
        else if(!dfs(v,3-c))return false;
    }
    return true;
}