二分图的判定(Bipartite graph pending)
//
// Created by LANSGANBS on 24-5-23.
//
/*
* code template: https://github.com/LANSGANBS/code-template
* local: C:\Users\18019\CLionProjects\.cpp-code
* URL: NULL
* Last_Status: NULL
* 写完这道就去原
*/
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl '\n'
#define buff ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define debug cout << "----------------------------------------------" <<endl
#define ture true
#define flase false
#define all(x) begin(x), end(x)
#define mem(a, x) memset(a, x, sizeof(a))
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a / gcd(a, b) * b)
#define sz(x) (int)x.size()
#define lowbit(x) (x & -x)
#define pb push_back
#define ll long long
#define int ll
#define ld long double
#define double ld
#define fr first
#define sc second
#define vi vector<int>
#define debug1(x) {cerr <<#x<<" = " <<x<<"\n"; };
#define debug2(x, y) {cerr <<#x<<" = " <<x<<", "<<#y <<" = " <<y <<"\n";};
#define debug3(x, y, z) {cerr <<#x<<" = " <<x<<", "<<#y <<" = " <<y <<", "<<#z<<" = "<<z<<"\n";};
#define debug4(x, y, z, w) {cerr <<#x<<" = " <<x<<", "<<#y <<" = " <<y <<", "<<#z<<" = "<<z<<", "<<#w << " = " <<w <<"\n";};
void yn(bool f)
{
cout << ((f == ture) ? "yes" : "no") << endl;
}
void YN(bool F)
{
cout << ((F == ture) ? "YES" : "NO") << endl;
}
i64 ceilDiv(i64 n, i64 m) // up
{
if (n >= 0)
{
return (n + m - 1) / m;
}
else
{
return n / m;
}
}
i64 floorDiv(i64 n, i64 m) // low
{
if (n >= 0)
{
return n / m;
}
else
{
return (n - m + 1) / m;
}
}
template<typename T1, typename T2>
istream &operator>>(istream &cin, pair<T1, T2> &a)
{
return cin >> a.first >> a.second;
}
template<typename T1>
istream &operator>>(istream &cin, vector<T1> &a)
{
for (auto &x: a)
{
cin >> x;
}
return cin;
}
template<typename T1, typename T2>
ostream &operator<<(ostream &cout, const pair<T1, T2> &a)
{
return cout << a.first << ' ' << a.second;
}
template<typename T1, typename T2>
ostream &operator<<(ostream &cout, const vector<pair<T1, T2>> &a)
{
for (auto &x: a)
{
cout << x << endl;
}
return cout;
}
template<typename T1>
ostream &operator<<(ostream &cout, const vector<T1> &a)
{
int n = a.size();
if (!n)
{
return cout;
}
cout << a[0];
for (int i = 1; i < n; i++)
{
cout << ' ' << a[i];
}
return cout;
}
#define C17
#ifdef C17
template<typename... Args>
auto mmax(Args... args)
{
return (std::max)({args...});
}
template<typename... Args>
auto mmin(Args... args)
{
return (std::min)({args...});
}
template<typename T, size_t N>
void debugarr(T (&arr)[N], int n)
{
cerr << "arr = ";
for (int i = 0; i < n; ++i)
{
cerr << arr[i] << ' ';
}
cerr << endl;
}
#endif
const int mod = 1e9 + 7;
#ifdef ONLINE_JUDGE
constexpr int N = 2e5 + 7;
#else
constexpr int N = 1e3 + 7;
#endif
const int M = 2 * N;
int n, m;
struct edge
{
int v, ne;
} e[M];
int h[N], idx;
int color[N];
void add(int a, int b)
{
e[++idx] = {b, h[a]};
h[a] = idx;
}
bool dfs(int u, int c)
{
color[u] = c;
for (int i = h[u]; i; i = e[i].ne)
{
int v = e[i].v;
if (!color[v])
{
if (dfs(v, 3 - c))
{
return ture;
}
}
else if (color[v] == c)
{
return ture;
}//有奇环
}
return false;
}
void solve()
{
cin >> n >> m;
for (int i = 0; i < m; i++)
{
int a, b;
cin >> a >> b;
add(a, b);
add(b, a);
}
bool flag = flase;
for (int i = 1; i <= n; i++)
{
if (!color[i])
{
if (dfs(i, 1))
{
flag = ture; // 有奇环
break;
}
}
}
if (flag)
{
cout << "No" << endl;
}
else
{
cout << "Yes" << endl;
}
}
signed main()
{
buff;
int tt = 1;
// cin >> tt;
while (tt--)
{
solve();
}
return 0;
}
标签:return,cout,int,graph,cin,template,operator,Bipartite,pending
From: https://www.cnblogs.com/LANSGANBS/p/18208084