#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int e[N], h[N], ne[N], idx;
void add(int a, int b)
{
e[++ idx] = b, ne[idx] = h[a], h[a] = idx;
}
int co[N];
bool check(int u, int c)
{
co[u] = c;
for(int i = h[u]; ~i; i = ne[i])
{
int j = e[i];
if(!co[j])
{
if(!check(j, 3 - c)) return false;
}
else if(co[j] == c) return false;
}
return true;
}
int main()
{
int n, m;
cin >> n >> m;
memset(h, -1, sizeof h);
for(int i = 1; i <= m; i ++)
{
int a, b;
cin >> a >> b;
add(a, b), add(b, a);
}
for(int i = 1; i <= n; i ++)
{
if(!co[i])
{
if(!check(i, 1))
{
cout << "No\n";
return 0;
}
}
}
cout << "Yes\n";
return 0;
}
标签:二分,匹配,最大,idx,int,ne,return,add,co
From: https://www.cnblogs.com/lfyszy/p/17334299.html