码迷,mamicode.com
首页 > 其他好文 > 详细

POJ 2492

时间:2015-06-11 12:30:48      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:

 1 #include<iostream>
 2 #include<stdio.h>
 3 #define MAXN 2050
 4 using namespace std;
 5 
 6 int pre[MAXN];
 7 int opp[MAXN];
 8 
 9 void init(int n)
10 {
11     int i;
12     for(i = 0; i <= n; ++ i)
13     {
14         pre[i] = i;
15         opp[i] = -1;
16     }
17 }
18 
19 int find_pre(int x)
20 {
21     if(pre[x] != x)
22     {
23         pre[x] = find_pre(pre[x]);
24     }
25     return pre[x];
26 }
27 
28 int comb(int x,int y)
29 {
30     if(x == -1)
31         return y;
32     if(y == -1)
33         return x;
34     pre[x] = y;
35     return y;
36 }
37 
38 int main()
39 {
40     //freopen("acm.acm","r",stdin);
41     int test;
42     int n;
43     int m;
44     int i;
45     int u;
46     int v;
47     int temp1;
48     int temp2;
49     bool boo;
50     bool bo;
51     int k;
52     scanf("%d",&test);
53     for(k = 0; k < test; ++ k)
54     {
55         scanf("%d%d",&n,&m);
56         init(n);
57         boo = false;
58 
59         cout<<"Scenario #"<<k+1<<":"<<endl;
60         for(i = 0; i < m; ++ i)
61         {
62             bo = false;
63             scanf("%d%d",&u,&v);
64             temp1 = u;
65             temp2 = v;
66             if(i != 0)
67             {
68                 temp1 = find_pre(temp1);
69                 temp2 = find_pre(temp2);
70                 if(temp1 == temp2)
71                 {
72                     boo = true;
73                 //    bo = true;
74                 }
75             }
76             if(!boo)
77             {
78                 u = find_pre(u);
79                 v = find_pre(v);
80                 temp1 = comb(u,opp[v]);
81                 temp2 = comb(opp[u],v);
82                 opp[temp1] = temp2;
83                 opp[temp2] = temp1;
84             }
85         }
86         if(boo)
87         {
88             cout<<"Suspicious bugs found!"<<endl;
89         }
90         else
91         {
92             cout<<"No suspicious bugs found!"<<endl;
93         }
94         cout<<endl;
95     }
96 }

 

POJ 2492

标签:

原文地址:http://www.cnblogs.com/gavinsp/p/4568442.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!