首页 > 其他分享 >二分图的判定(Bipartite graph pending)

二分图的判定(Bipartite graph pending)

时间:2024-05-23 11:42:09浏览次数:9  
标签:return cout int graph cin template operator Bipartite pending

二分图的判定(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

相关文章

  • 论文阅读:Multi-Grained Dependency Graph Neural Network for Chinese Open Informati
    LyuZ,ShiK,LiX,etal.Multi-graineddependencygraphneuralnetworkforChineseopeninformationextraction[C]//Pacific-AsiaConferenceonKnowledgeDiscoveryandDataMining.Cham:SpringerInternationalPublishing,2021:155-167.MGD-GNN开源代码引言......
  • 【论文阅读】FlexGraph: A Flexible and Efficient Distributed Framework for GNN Tr
    阅读思考问题:PleasebrieflydescribehowhierarchicaldependencygraphsarebuiltinFlexGraph,andpointoutthespecificstageintheNAUabstractionwherethisprocesstakesplace.请简要描述在FlexGraph中如何构建分层依赖图,并指出在NAU抽象中的具体阶段发生此......
  • B. Mahmoud and Ehab and the bipartiteness
    原题链接题解观察一个二分图会发现同一组的节点不直接相连二分图能够建立的最多的边等于\(n*m\)code#include<bits/stdc++.h>usingnamespacestd;#definelllonglongvector<ll>G[100005];lldepth[100005]={0};llodd=0,even=0;voiddfs(llnow,llfa){i......
  • Vue-与-GraphQL-应用构建指南-全-
    Vue与GraphQL应用构建指南(全)原文:zh.annas-archive.org/md5/60CC414A1AE322EC97E6A0F8A5BBE3AD译者:飞龙协议:CCBY-NC-SA4.0前言自2012年Facebook发布以来,GraphQL已经席卷了互联网。像Airbnb和Audi这样的大公司已经开始采用它,而中小型公司现在也意识到了这种基......
  • 以MIT实验Turtle Graphcis为例,探讨底层实现和复用相关
    ​在我们软件构造实验中,包含了MIT的原实验TurtleGraphcis的任务,接下来我就在完成这一实验过程中的思考谈谈个人关于底层实现和复用相关的观点。​ MIT的原实验页面链接为http://web.mit.edu/6.031/www/fa18/psets/ps0/,通过阅读页面我们可以了解这一实验的目的。简要来......
  • [Paper Reading] OFT Orthographic Feature Transform for Monocular 3D Object Detec
    OFTOrthographicFeatureTransformforMonocular3DObjectDetectionOFTOrthographicFeatureTransformforMonocular3DObjectDetection时间:18.11机构:UniversityofCambridgeTL;DR当时纯视觉自动驾驶方案效果上仅达到Lidar方案有10%的水平,本文claim部分差距源于pe......
  • B. Greg and Graph
    题意:n个节点的图,每次操作删除一个节点。求每次操作之前,所有的图中的有序对(i,j)的最短路径之和。思路:n<=500,弗洛伊德最短路径算法。因为每次的操作是删除节点,所以可以考虑将操作反着来,每次往图中添加节点,每添加一个节点更新一下最短路径。总结:因为要添加的节点已经存储在了......
  • Graph Theory books and authors
    图论大师:JohnAdrianBondy写了两本图论巨著:GraphTheorywithApplicationsJohnAdrianBondyNorthHollandGraphTheoryAdrianBondy,U.S.R.MurtySpringer  https://www.iro.umontreal.ca/~hahn/IFT3545/https://www.iro.umontreal.ca/~hahn/法语 http://www.ma......
  • 华为云FunctionGraph构建高可用系统的实践
    本文分享自华为云社区《华为云FunctionGraph构建高可用系统的实践》,作者:华为云PaaS服务小智。导语每年,网上都会报道XXX系统异常不可用,给客户带来巨大的经济损失。云服务的客户基数更大,一旦出现问题,都将给客户和服务自身带来极大影响。本文将基于华为云FunctionGraph自身的实践,......
  • 论文笔记-Machine learning based flow regime recognition in helically coiled tube
    对象:进行了螺旋线圈中的自动两相流模式识别方法:X射线照相的空隙率测量数据+聚类+KNN、RF、SVM目标:模式识别关注特征:结果:聚类分类:模型是随机森林(RF)分类器、KNN分类器和SVM(参见第1节)。为了优化超参数并估计分类器精度,所有模型均采用嵌套5×5交叉验证方案,如图1所示。......