//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<cstdlib>
#include<set>
#include<stack>
#include<cstring>
using namespace std;
template<class T>inline T read(T&x)
{
char c;
while((c=getchar())<=32)if(c==EOF)return -1;
bool ok=false;
if(c=='-')ok=true,c=getchar();
for(x=0; c>32; c=getchar())
x=x*10+c-'0';
if(ok)x=-x;
return 1;
}
template<class T> inline T read_(T&x,T&y)
{
return read(x)!=-1&&read(y)!=-1;
}
template<class T> inline T read__(T&x,T&y,T&z)
{
return read(x)!=-1&&read(y)!=-1&&read(z)!=-1;
}
template<class T> inline void write(T x)
{
if(x<0)putchar('-'),x=-x;
if(x<10)putchar(x+'0');
else write(x/10),putchar(x%10+'0');
}
template<class T>inline void writeln(T x)
{
write(x);
putchar('\n');
}
//-------ZCC IO template------
const int maxn=101;
const double inf=999999999;
#define lson (rt<<1),L,M
#define rson (rt<<1|1),M+1,R
#define M ((L+R)>>1)
#define For(i,t,n) for(int i=(t);i<(n);i++)
typedef long long LL;
typedef double DB;
typedef pair<int,int> P;
#define bug printf("---\n");
#define mod 10007
int V,E;
vector<int> G[maxn];
int color[maxn];
bool dfs(int v,int c)
{
color[v]=c;
int N=G[v].size();
for(int i=0; i<N; i++)
{
if(color[G[v][i]]==c)return false;
if(color[G[v][i]]==0&&!dfs(G[v][i],-c))return false;
}
return true;
}
void solve()
{
memset(color,0,sizeof(color));
for(int i=1; i<=V; i++)
{
if(color[i]==0)
{
if(!dfs(i,1))
{
printf("Wrong\n");
return ;
}
}
}
puts("Correct");
}
int main()
{
//#ifndef ONLINE_JUDGE
//freopen("in.txt","r",stdin);
// #endif // ONLINE_JUDGE
int n,m,i,j,k,t;
int T;
read(T);
while(T--)
{
read_(V,m);
while(m--)
{
int a,b;
read_(a,b);
G[a].push_back(b);
G[b].push_back(a);
}
solve();
For(i,0,V+1)G[i].clear();
}
return 0;
}
#1121 : 二分图一?二分图判定 (HIHOCoder +二分图的判定)
原文:http://blog.csdn.net/u013167299/article/details/44995831