题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1829
不想说了,说多了都是泪啊....
本来用dsu已经过了,看了discuss可以用二分图过掉,思考一波,敲完代码提交,直接wa到死啊,看了讨论版测试了几组样例都能过,wa了十几发到现在也不知道为什么啊啊啊啊啊...心好累..
用0,1表示不同性别的人,若两者性别不同则合并,否则直接break掉。
具体见代码(那个喳喳二分图代码只能丢掉了..反正也不是正解o(︶︿︶)o):
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <sstream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <list>
#include <set>
//#define ONLINE_JUDGE
#define eps 1e-6
#define INF 0x7fffffff //INT_MAX
#define inf 0x3f3f3f3f //int??????????????????
#define FOR(i,a) for((i)=0;i<(a);(i)++) //[i,a);
#define MEM(a) (memset((a),0,sizeof(a)))
#define sfs(a) scanf("%s",a)
#define sf(a) scanf("%d",&a)
#define sfI(a) scanf("%I64d",&a)
#define pf(a) printf("%d\n",a)
#define pfI(a) printf("%I64d\n",a)
#define pfs(a) printf("%s\n",a)
#define sfd(a,b) scanf("%d%d",&a,&b)
#define sft(a,b,c)scanf("%d%d%d",&a,&b,&c)
#define for1(i,a,b) for(int i=(a);i<b;i++)
#define for2(i,a,b) for(int i=(a);i<=b;i++)
#define for3(i,a,b)for(int i=(b);i>=a;i--)
#define MEM1(a) memset(a,0,sizeof(a))
#define MEM2(a) memset(a,-1,sizeof(a))
#define MEM3(a) memset(a,0x3f,sizeof(a))
#define MEMS(a) memset(a,'\0',sizeof(a))
#define LL __int64
const double PI = acos(-1.0);
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> inline T Min(T a, T b) { return a < b ? a : b; }
template<class T> inline T Max(T a, T b) { return a > b ? a : b; }
using namespace std;
template<class T>
T Mint(T a, T b, T c) {
if (a>b) {
if (c>b)
return b;
return c;
}
if (c>a)
return a;
return c;
}
template<class T>
T Maxt(T a, T b, T c) {
if (a>b) {
if (c>a)
return c;
return a;
}
else if (c > b)
return c;
return b;
}
const int maxn=2005;
int T,n,m;
int f[maxn],r[maxn];
void Make_Set(int x){
f[x]=x;
r[x]=0;
}
int find(int x){//带权压缩路径
if(x==f[x]) return x;
int tmp=f[x];
f[x]=find(f[x]);
r[x]+=r[tmp];
r[x]%=2;//性别标记为0 or 1
return f[x];
}
bool Union(int a,int b){//按秩合并
int ra=find(a);
int rb=find(b);
if(ra==rb){
if(r[a]==r[b])
return false;
}
f[ra]=rb;
r[ra]=(r[b]+1-r[a])%2;
return true;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("test.in","r",stdin);
freopen("test.out","w",stdout);
#endif
int cas=1;
sf(T);
while(T--){
sfd(n,m);
for2(i,0,n) Make_Set(i);//初始化
int a,b;
bool flag=true;
while(m--){
sfd(a,b);
if(!flag) continue;//若已存在不符合条件的情况,则不需继续判断
if(!Union(a,b)){
flag=false;
}
}
printf("Scenario #%d:\n",cas++);
if(flag) puts("No suspicious bugs found!");
else puts("Suspicious bugs found!");
putchar(10);
}
return 0;
}