二分图染色

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <cstdlib>
#include <ctime>
#include <time.h>

inline int Rand (){ return (rand () << 16) | rand ();}
//#define fi first
//#define se second
//#define mp make_pair
//#define sz(x) ( (int) (x).size ())
#define abs(x) ((x) < 0 ? -(x) : (x))
#define INF 20000000000000000ll
//#define sqr(x) ( (x) * (x))
//#define all(x) x.begin (), x.end ()
//#define files(x) freopen (x".in", "r", stdin); freopen (x".out", "w", stdout);
//#define MOD 1000000007
//#define y1 google
#define eps 1e-9
//#define tim ((clock() * 1.0) / CLOCKS_PER_SEC)
#define sf scanf
#define pf printf
#define fup(a,b) for(int i=a;i<=b;i++)
#define fdown(a,b) for(int i=a;i>=b;i--)
#define min(a,b) a>b?b:a
#define max(a,b) a>b?a:b
#define FP freopen("a.txt","r",stdin)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

const int maxn=300;
vector<int>G[maxn];
int color[maxn];
int V,E;

bool dfs(int v,int c)
{
	color[v]=c;
	for(int i=0;i<G[v].size();i++)
	{
		if(color[G[v][i]]==c) return false;
		if(color[G[v][i]]==0) if(dfs(G[v][i],-c)) return true;
	}
	return true;
}

void solve()
{
	memset(color,0,sizeof(color));
	for(int i=0;i<V;i++)
		if(color[i]==0)
			if(!dfs(i,0))
				{cout<<"no"<<endl;return;}
	pf("ok\n");
}


int main()
{
	while(1)
	{
		cin>>V>>E;
		fup(1,E)
		{
			int s,t;
			cin>>s>>t;
			G[s].push_back(t);
		}
		solve();
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值