标签:
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 11981 Accepted Submission(s): 3901
/* *********************************************** Author :pk28 Created Time :2015/8/15 9:54:22 File Name :4.cpp ************************************************ */ #include <iostream> #include <cstring> #include <cstdlib> #include <stdio.h> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <iomanip> #include <list> #include <deque> #include <stack> #define ull unsigned long long #define ll long long #define mod 90001 #define INF 0x3f3f3f3f #define maxn 3000+10 #define cle(a) memset(a,0,sizeof(a)) const ull inf = 1LL << 61; const double eps=1e-5; using namespace std; bool cmp(int a,int b){ return a>b; } int fa[maxn]; int d[maxn]; int n,m,mark; void init(){ for(int i=1;i<=n+5;i++){ d[i]=0; fa[i]=i; } mark=0; } int findfa(int x){ if(x==fa[x])return x; else{ int root=findfa(fa[x]); d[x]+=d[fa[x]];//记录到根节点的距离 fa[x]=root; return fa[x]; } } void Union(int a,int b){ int x=findfa(a); int y=findfa(b); if(x==y){ if((d[a]&1)==(d[b]&1))mark=1; return ; } else{ fa[x]=y; d[x]=(d[a]+d[b]+1); } } int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif //freopen("out.txt","w",stdout); int T; cin>>T; int a,b; int cnt=1; while(T--){ scanf("%d%d",&n,&m); init(); for(int i=0;i<m;i++){ scanf("%d %d",&a,&b); if(mark)continue; Union(a,b); } printf("Scenario #%d:\n",cnt++); if(mark)printf("Suspicious bugs found!\n"); else printf("No suspicious bugs found!\n"); printf("\n"); } return 0; }
HDU 1829/POJ 2492 A Bug's Life
标签:
原文地址:http://www.cnblogs.com/pk28/p/4732059.html