zoukankan      html  css  js  c++  java
  • poj 2492

    A Bug's Life
    Time Limit: 10000MS   Memory Limit: 65536K
    Total Submissions: 41952   Accepted: 13619

    Description

    Background 
    Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that they only interact with bugs of the opposite gender. In his experiment, individual bugs and their interactions were easy to identify, because numbers were printed on their backs. 
    Problem 
    Given a list of bug interactions, decide whether the experiment supports his assumption of two genders with no homosexual bugs or if it contains some bug interactions that falsify it.

    Input

    The first line of the input contains the number of scenarios. Each scenario starts with one line giving the number of bugs (at least one, and up to 2000) and the number of interactions (up to 1000000) separated by a single space. In the following lines, each interaction is given in the form of two distinct bug numbers separated by a single space. Bugs are numbered consecutively starting from one.

    Output

    The output for every scenario is a line containing "Scenario #i:", where i is the number of the scenario starting at 1, followed by one line saying either "No suspicious bugs found!" if the experiment is consistent with his assumption about the bugs' sexual behavior, or "Suspicious bugs found!" if Professor Hopper's assumption is definitely wrong.

    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!

    感觉像套模板似的qwq。
     1 #include<cstdio>
     2 #include<cstring>
     3 using namespace std;
     4 const int maxn=2006;
     5 int fa[maxn],val[maxn];
     6 
     7 void init()
     8 {
     9     for(int i=0;i<maxn;i++){
    10         fa[i]=i;
    11         val[i]=0;
    12     }
    13 }
    14 
    15 int find_fa(int x)
    16 {
    17     if(fa[x]==x) return x;
    18     int tmp=fa[x];
    19     fa[x]=find_fa(tmp);
    20     val[x]=val[x]^val[tmp];
    21     return fa[x];
    22 }
    23 
    24 int main()
    25 {
    26     int T;
    27     scanf("%d",&T);
    28     for(int kkk=1;kkk<=T;kkk++){
    29         int n,m;
    30         scanf("%d%d",&n,&m);
    31         init();
    32         int ans=0;
    33         for(int i=1;i<=m;i++){
    34             int x,y;
    35             scanf("%d%d",&x,&y);
    36             int opx,opy,tmp=1;
    37             opx=find_fa(x);
    38             opy=find_fa(y);
    39             if(opx!=opy){
    40                 fa[opy]=opx;
    41                 val[opy]=val[x]^val[y]^tmp;
    42             }
    43             if(opx==opy&&val[x]^val[y]!=tmp){
    44                 ans=1;
    45             }
    46         }
    47         printf("Scenario #%d:
    ",kkk);
    48         if(ans==1) printf("Suspicious bugs found!
    
    ");
    49         else printf("No suspicious bugs found!
    
    ");
    50     }
    51     return 0;
    52 }
  • 相关阅读:
    java注解说明
    paypal
    eclispe查看jdk源码后特别卡顿导致未响应解决
    ubuntu+tomcat,多环境、自动化部署脚本,git+maven+tomcat+ubuntu
    ubuntu+let's encrypt生成永久免费https证书 ubuntu+tomcat+nginx+let's encrypt
    MySQL创建数据库与创建用户以及授权
    linux查找并杀死进程shell
    redmine安装笔记
    C#动态获取本机可用串口的两种方式
    C# 控件缩写规范
  • 原文地址:https://www.cnblogs.com/ZQUACM-875180305/p/9108737.html
Copyright © 2011-2022 走看看