标签:art because cstring strong ini single find bit sum
Input
Output
Sample Input
2 3 3 1 2 2 3 1 3 4 2 1 2 3 4
Sample Output
Scenario #1: Suspicious bugs found! Scenario #2: No suspicious bugs found!
Hint
1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #include <cstdio> 5 #include <vector> 6 #include <cstdlib> 7 #include <iomanip> 8 #include <cmath> 9 #include <ctime> 10 #include <map> 11 #include <set> 12 #include <queue> 13 using namespace std; 14 #define lowbit(x) (x&(-x)) 15 #define max(x,y) (x>y?x:y) 16 #define min(x,y) (x<y?x:y) 17 #define MAX 100000000000000000 18 #define MOD 1000000007 19 #define pi acos(-1.0) 20 #define ei exp(1) 21 #define PI 3.141592653589793238462 22 #define INF 0x3f3f3f3f3f 23 #define mem(a) (memset(a,0,sizeof(a))) 24 typedef long long ll; 25 ll gcd(ll a,ll b){ 26 return b?gcd(b,a%b):a; 27 } 28 const int N=2005; 29 const int mod=1e9+7; 30 int n,q; 31 int fath[2005],a[2005]; 32 void init() 33 { 34 for(int i=1;i<=n;i++){ 35 fath[i]=i; 36 a[i]=0; 37 } 38 } 39 int findd(int x) 40 { 41 if(x==fath[x])return x; 42 int y=findd(fath[x]); 43 a[x]=(a[x]+a[fath[x]])&1; 44 fath[x]=y; 45 return y; 46 } 47 bool SetUnion(int x,int y) 48 { 49 int fx=findd(x); 50 int fy=findd(y); 51 if(fx==fy){ 52 if(a[x]==a[y]) return true; 53 else return false; 54 } 55 fath[fx]=fy; 56 if(a[y]){ 57 a[fx]=a[x]; 58 } 59 else{ 60 a[fx]=1-a[x]; 61 } 62 return false; 63 } 64 int main() 65 { 66 int t,case1=1,x,y; 67 scanf("%d",&t); 68 while(t--){ 69 bool flat=true; 70 scanf("%d%d",&n,&q); 71 init(); 72 for(int i=0;i<q;i++){ 73 scanf("%d%d",&x,&y); 74 if(SetUnion(x,y))flat=false; 75 } 76 printf("Scenario #%d:\n",case1++); 77 if(!flat)puts("Suspicious bugs found!\n"); 78 else puts("No suspicious bugs found!\n"); 79 } 80 return 0; 81 }
标签:art because cstring strong ini single find bit sum
原文地址:http://www.cnblogs.com/shixinzei/p/7272687.html