2013
11-11

# A Bug’s Life

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.

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.

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.

2
3 3
1 2
2 3
1 3
4 2
1 2
3 4

Scenario #1:
Suspicious bugs found!

Scenario #2:
No suspicious bugs found!

Huge input,scanf is recommended.

//* @author: [email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */
import java.io.*;
public class Main
{
static my[] p;
public static void main(String[] args) throws IOException
{
int cnt=0;
while((a--)!=0)
{
cnt++;
int n=Integer.parseInt(ss[0]);
p=new my[n+1];
for(int i=0;i<=n;i++)
p[i]=new my(i);
int t=Integer.parseInt(ss[1]);
boolean bb=true;
while((t--)!=0)
{
if(bb)
{
int x1=Integer.parseInt(ss[0]);
int x2=Integer.parseInt(ss[1]);
int r1=root(x1),r2=root(x2);
if(r1< r2){
p[r2].root=r1;
p[x2].d=(p[x1].d+1)%2;
}
else if(r1>r2){
p[r1].root=r2;
p[x1].d=(p[x2].d+1)%2;
}
else if(p[x2].d==p[x1].d)bb=false;
}
}
System.out.println("Scenario #"+cnt+":");
if(bb)System.out.println("No suspicious bugs found!");
else System.out.println("Suspicious bugs found!");
System.out.println();
}
}

static int root(int a)
{
int u=a;
while(p[a].root!=a)a=p[a].root;
p[u].root=a;
return a;
}

}

class my
{
int root;
int d=0;
public my(int r)
{
root=r;
}
}

1. 很高兴你会喜欢这个网站。目前还没有一个开发团队，网站是我一个人在维护，都是用的开源系统，也没有太多需要开发的部分，主要是内容整理。非常感谢你的关注。

2. 如果两个序列的最后字符不匹配（即X [M-1]！= Y [N-1]）
L（X [0 .. M-1]，Y [0 .. N-1]）= MAX（L（X [0 .. M-2]，Y [0 .. N-1]），L（X [0 .. M-1]，Y [0 .. N-1]）
这里写错了吧。