二分图匹配 判断是否为二分图 —— 模板

来源:互联网 发布:淘宝美工助理工作内容 编辑:程序博客网 时间:2024/06/08 06:40
bool g[maxn][maxn];int col[maxn];//利用0,1染色,层序遍历,用同色则为falsebool bfs(int n){    memset(col,-1,sizeof(col));    for(int i = 0; i < n; i++)    {        if(col[i] != -1) continue;        queue<int> q;        col[i] = 1;        q.push(i);        while(!q.empty())        {            int from = q.front();            q.pop();            for(int to = 0; to < n; to++)            {                if(g[from][to] && col[to] == -1)                {                    col[to] = !col[from];                    q.push(to);                }                if(g[from][to] && col[to] == col[from])                    return false;            }        }    }    return true;}
原创粉丝点击