bool g[maxn][maxn];
int col[maxn];
//利用0,1染色,层序遍历,用同色则为false
bool 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;
}
二分图匹配 判断是否为二分图 —— 模板
最新推荐文章于 2021-08-07 18:29:50 发布