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.

  判断奇环,二分染色bfs,并查集都可做。

代码如下:

// ━━━━━━神兽出没━━━━━━
// ┏┓ ┏┓
// ┏┛┻━━━━━━━┛┻┓
// ┃ ┃
// ┃ ━ ┃
// ████━████ ┃
// ┃ ┃
// ┃ ┻ ┃
// ┃ ┃
// ┗━┓ ┏━┛
// ┃ ┃
// ┃ ┃
// ┃ ┗━━━┓
// ┃ ┣┓
// ┃ ┏┛
// ┗┓┓┏━━━━━┳┓┏┛
// ┃┫┫ ┃┫┫
// ┗┻┛ ┗┻┛
//
// ━━━━━━感觉萌萌哒━━━━━━ // Author : WhyWhy
// Created Time : 2015年07月17日 星期五 20时49分42秒
// File Name : 2492.cpp #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h> using namespace std; const int MaxN=; int map1[MaxN][MaxN];
int flag=;
int vis[MaxN];
int N;
int que[MaxN],first,last; bool bfs(int u)
{
int v; first=last=;
que[last++]=u;
vis[u]=; while(last-first)
{
u=que[first++]; for(v=;v<=N;++v)
if(map1[u][v]==flag && v!=u)
{
if(vis[v]==vis[u])
return ; if(!vis[v])
{
vis[v]=-vis[u];
que[last++]=v;
}
}
} return ;
} bool getans()
{
memset(vis,,sizeof(vis));
first=last=; for(int i=;i<=N;++i)
if(!vis[i])
if(bfs(i))
return ; return ;
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout); int T,cas=;
int Q;
int a,b; scanf("%d",&T); while(T--)
{
scanf("%d %d",&N,&Q);
++flag; while(Q--)
{
scanf("%d %d",&a,&b);
map1[a][b]=map1[b][a]=flag;
} printf("Scenario #%d:\n",cas++); if(getans())
puts("Suspicious bugs found!\n");
else
puts("No suspicious bugs found!\n");
} return ;
}

(简单) POJ 2492 A Bug's Life,二分染色。的更多相关文章

  1. poj 2492 A Bug's Life 二分图染色 || 种类并查集

    题目链接 题意 有一种\(bug\),所有的交往只在异性间发生.现给出所有的交往列表,问是否有可疑的\(bug\)(进行同性交往). 思路 法一:种类并查集 参考:https://www.2cto.c ...

  2. poj 2492 a bug's life 简单带权并查集

    题意大致为找同性恋的虫子.... 这个比食物链要简单些.思路完全一致,利用取余操作实现关系之间的递推. 个人感觉利用向量,模和投影可能可以实现具有更加复杂关系的并查集. #include<ios ...

  3. hdu - 1829 A Bug's Life (并查集)&&poj - 2492 A Bug's Life && poj 1703 Find them, Catch them

    http://acm.hdu.edu.cn/showproblem.php?pid=1829 http://poj.org/problem?id=2492 臭虫有两种性别,并且只有异性相吸,给定n条臭 ...

  4. POJ 2492 A Bug's Life(并查集)

    http://poj.org/problem?id=2492 题意 :就是给你n条虫子,m对关系,每一对关系的双方都是异性的,让你找出有没有是同性恋的. 思路 :这个题跟POJ1703其实差不多,也是 ...

  5. POJ 2492 A Bug's Life(带权并查集)

    题目链接:http://poj.org/problem?id=2492 题目大意:有n只虫子,m对关系,m行每行有x y两个编号的虫子,告诉你每对x和y都为异性,先说的是对的,如果后面给出关系与前面的 ...

  6. POJ 2492 A Bug's Life (带权并查集 && 向量偏移)

    题意 : 给你 n 只虫且性别只有公母, 接下来给出 m 个关系, 这 m 个关系中都是代表这两只虫能够交配, 就是默认异性, 问你在给出的关系中有没有与异性交配这一事实相反的, 即同性之间给出了交配 ...

  7. POJ 2492 A Bug's Life

    传送门:A Bug's Life Description Background Professor Hopper is researching the sexual behavior of a rar ...

  8. POJ 2492 A Bug's Life (并查集)

    A Bug's Life Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 30130   Accepted: 9869 De ...

  9. POJ 2492 A Bug's Life (并查集)

    Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes ...

随机推荐

  1. wpf计时器

    wpf应用程序间隔一段时间触发一个事件,代码如下: public MainWindow() { InitializeComponent(); DispatcherTimer timer = new D ...

  2. Android按钮单击事件的四种常用写法总结

    很多学习Android程序设计的人都会发现每个人对代码的写法都有不同的偏好,比较明显的就是对控件响应事件的写法的不同.因此本文就把这些写法总结一下,比较下各种写法的优劣,希望对大家灵活地选择编码方式可 ...

  3. Java获取来访者IP

    在JSP里,获取客户端的IP地址的方法是:request.getRemoteAddr(),这种方法在大部分情况下都是有效的.但是在通过了Apache,Squid等反向代理软件就不能获取到客户端的真实I ...

  4. hdu1426 Sudoku Killer

    Sudoku Killer Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total ...

  5. NGUI 添加回调函数

    //缓动完成 TweenPosition tweenPos=GetComponent<TweenPosition>(); tweenPos.AddOnFinished(complete); ...

  6. Python虚拟环境安装virtualenv

    解决了多个版本共存的问题 virtualenv 为每个不同项目提供一份 Python 安装.它并没有真正安装多个 Python 副本,但是它确实提供了一种巧妙的方式来让各项目环境保持独立. 安装vir ...

  7. Linux学习 -- Shell基础 -- 概述

    Shell是什么? 命令解释器 编程语言 Linux支持的Shell类型 cat /etc/shells 主要学习 bash 脚本执行方式 echo echo -e 单引号 -- 原始字符串  双引号 ...

  8. IOS小工具以及精彩的博客

    IOS小工具以及精彩的博客 工具 Log Guru是一个收集Log的小工具, 可以在 Mac 上查看 iOS 设备的实时系统日志. 现在可以直接高亮显示在 FIR.im 上安装 app 失败的原因.后 ...

  9. 链接libtorrent库时出现的问题

    在QtCreator中使用libtorrent库的时候, 项目配置中 libs项配置如下: LIBS += -liconv -ltorrent-rasterbar -lboost_system -lb ...

  10. VirtualBox中CentOS通过Host-Only方式实现虚拟机主机互相访问、共享上网

    VirtualBox常用的网络配置如下: 连接方式 主机访问虚拟机 虚拟机访问主机 虚拟机访问虚拟机 虚拟机访问外网 说明 网络地址转换(NAT) 不支持 支持 不支持 支持 默认连接方式,虚拟IP, ...