Time Limit: 1000MS   Memory Limit: 131072KB   64bit IO Format: %I64d & %I64u

Submit
Status

Description

liympanda, one of Ikki’s friend, likes playing games with Ikki. Today after minesweeping with Ikki and winning so many times, he is tired of such easy games and wants to play another game with Ikki.

liympanda has a magic circle and he puts it on a plane, there are n points on its boundary in circular border: 0, 1, 2, …,
n − 1. Evil panda claims that he is connecting m pairs of points. To connect two points, liympanda either places the link entirely inside the circle or entirely outside the circle. Now liympanda tells Ikki no two links touch inside/outside the circle,
except on the boundary. He wants Ikki to figure out whether this is possible…

Despaired at the minesweeping game just played, Ikki is totally at a loss, so he decides to write a program to help him.

Input

The input contains exactly one test case.

In the test case there will be a line consisting of of two integers: n and
m (n ≤ 1,000, m ≤ 500). The following m lines each contain two integers
ai and bi, which denote the endpoints of the
ith wire. Every point will have at most one link.

Output

Output a line, either “panda is telling the truth...” or “the evil panda is lying again”.

Sample Input

4 2
0 1
3 2

Sample Output

panda is telling the truth...

Source

POJ Monthly--2007.03.04, Ikki

#include<stdio.h>
#include<string.h>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;
#define MAX 100000+10
int low[MAX],dfn[MAX];
int sccno[MAX];
int scc_cnt,dfs_clock,cnt;
bool Instack[MAX];
int m,n,num1[MAX],num2[MAX];
vector<int>G[MAX];
stack<int>s;
struct node
{
int u,v;
int next;
}edge[MAX*2];
void init()
{
for(int i=1;i<=3*m;i++)
G[i].clear(); }
bool judge(int a, int b, int c, int d)
{
return (c > a && b > c && d > b) || (a > c && d > a && b > d);
}
void getmap()
{
for(int i=1;i<=m;i++)
scanf("%d%d",&edge[i].u,&edge[i].v);
for(int i=1;i<=m;i++)
{
for(int j=1;j<i;j++)
{//如果会相交的话
if(judge(edge[i].u,edge[i].v,edge[j].u,edge[j].v))
{
G[i+2*m].push_back(j+m);//i边j边在里在外,四种情况
G[i+m].push_back(j+2*m);
G[j+m].push_back(i+2*m);
G[j+2*m].push_back(i+m);
}
}
}
}
void tarjan(int u,int fa)
{
int v;
low[u]=dfn[u]=++dfs_clock;
s.push(u);
Instack[u]=true;
for(int i=0;i<G[u].size();i++)
{
v=G[u][i];
if(!dfn[v])
{
tarjan(v,u);
low[u]=min(low[v],low[u]);
}
else if(Instack[v])
low[u]=min(low[u],dfn[v]);
}
if(low[u]==dfn[u])
{
++scc_cnt;
for(;;)
{
v=s.top();
s.pop();
Instack[v]=false;
sccno[v]=scc_cnt;
if(v==u) break;
}
}
}
void find(int l,int r)
{
memset(Instack,false,sizeof(Instack));
memset(sccno,0,sizeof(sccno));
memset(dfn,0,sizeof(dfn));
memset(low,0,sizeof(low));
scc_cnt=dfs_clock=0;
for(int i=l;i<=r;i++)
if(!dfn[i])
tarjan(i,-1);
}
void solve()
{
int flog=1;
for(int i=1;i<=m;i++)
{
if(sccno[i+m]==sccno[i+2*m])
{
flog=0;
printf("the evil panda is lying again\n");
break;
}
}
if(flog)
printf("panda is telling the truth...\n");
}
int main()
{
scanf("%d%d",&n,&m);
init();
getmap();
find(1,3*n);
solve();
return 0;
}

poj--3207--Ikki's Story IV - Panda's Trick(2-sat)的更多相关文章

  1. POJ 3207 Ikki's Story IV - Panda's Trick(2-sat问题)

    POJ 3207 Ikki's Story IV - Panda's Trick(2-sat问题) Description liympanda, one of Ikki's friend, likes ...

  2. POJ 3207 Ikki's Story IV - Panda's Trick (2-sat)

    Ikki's Story IV - Panda's Trick Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 6691   ...

  3. poj 3207 Ikki's Story IV - Panda's Trick (2-SAT)

    http://poj.org/problem?id=3207 Ikki's Story IV - Panda's Trick Time Limit: 1000MS   Memory Limit: 13 ...

  4. POJ 3207 Ikki's Story IV - Panda's Trick

    Ikki's Story IV - Panda's Trick Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 7296   ...

  5. POJ 3207 Ikki's Story IV - Panda's Trick (2-SAT,基础)

    题意: 有一个环,环上n个点,现在在m个点对之间连一条线,线可以往圆外面绕,也可以往里面绕,问是否必定会相交? 思路: 根据所给的m条边可知,假设给的是a-b,那么a-b要么得绕环外,要么只能在环内, ...

  6. poj 3207 Ikki's Story IV - Panda's Trick【2-SAT+tarjan】

    注意到相交的点对一定要一里一外,这样就变成了2-SAT模型 然后我建边的时候石乐志,实际上不需要考虑这个点对的边是正着连还是反着连,因为不管怎么连,能相交的总会相交,所以直接判相交即可 然后tarja ...

  7. POJ 3207 Ikki's Story IV - Panda's Trick 2-sat模板题

    题意: 平面上,一个圆,圆的边上按顺时针放着n个点.现在要连m条边,比如a,b,那么a到b可以从圆的内部连接,也可以从圆的外部连接.给你的信息中,每个点最多只会连接的一条边.问能不能连接这m条边,使这 ...

  8. 【POJ】3207 Ikki's Story IV - Panda's Trick

    http://poj.org/problem?id=3207 题意:一个圆上顺时针依次排列着标号为1-n的点,这些点之间共有m条边相连,每两个点只能在圆内或者圆外连边.问是否存在这些边不相交的方案.( ...

  9. 【poj3207】Ikki's Story IV - Panda's Trick(2-sat)

    传送门 题意: 给出一个圆,圆上有\(n\)个点,依次为\(0,1,\cdots,n-1\). 现在要连接\(m\)对点,每次连接时可以直接从里面连,也可以从外面连. 最后问,连完这\(m\)对点后, ...

  10. 【POJ3207】Ikki's Story IV - Panda's Trick

    POJ 3207 Ikki's Story IV - Panda's Trick liympanda, one of Ikki's friend, likes playing games with I ...

随机推荐

  1. SSRS 报表 如何加参数

    SSRS 报表 如何加参数 连接上以后出现一个问题 就是给报表加上参数以后报表不断刷新,跟上次那个报表刷新是同样的问题.那么下面我们来解决一下. 1. 这是给报表添加默认参数进入页面后就不断的刷新刷新 ...

  2. 获取远程请求的IP地址、本机Mac地址和客户端Mac地址

    我在近期项目里面去记录异常日志时,用到了这两个地址,也是从网上和前辈那里学习到的,本人项目是MVC框架的,自己整理了一个公共方法类,包括获取远程客户端IP和Mac地址,以及获取本机Mac地址的方法,代 ...

  3. Super超级ERP系统---(4)采购管理--采购单创建

    Erp系统中采购是系统必不可少的一部分,也就是ERP种的进货模块,超级ERP系统中的采购模块选选择采购供应商,然后选择进货商品的数量和采购价格,创建采购进货单 1.创建采购单 2.审核采购单 采购单创 ...

  4. WinForm上传文件,下载文件

    上传文件: 使用OpenFileDialog控件选择文件, 具体代码示例: private void btnUpLoadPic_Click(object sender, EventArgs e) { ...

  5. 自制滑杆slider

    一.效果图 二.HTML结构 <div id="d2"> <p>自制可拖动滑块:</p> <div id="out"& ...

  6. meta标签的作用及整理

    [转载] meta的标签的使用是我在前端学习中曾经困惑过一段时间的问题.一方面不是很了解meta标签的用途,另一方面是对于meta标签里的属性和值不是懂,也不知道从哪里冒出来的,所以这篇文章专门整理下 ...

  7. nodejs supervisor安装

    使用supervisor提高nodejs调试效率 用超级用户运行npm -g install supervisor命令,说是顺 >$ sudo npm -g install supervisor ...

  8. 仅前端cookie之记住密码

    参考文章给忘了...,我就在他基础上修改了一些,但至于安全性,我没弄md5,所以安全系数应该为0 <!DOCTYPE html> <html lang="en"& ...

  9. Spring AOP 介绍与基于接口的实现

    热烈推荐:超多IT资源,尽在798资源网 声明:转载文章,为防止丢失所以做此备份. 本文来自公众号:程序之心 原文地址:https://mp.weixin.qq.com/s/vo94gVyTss0LY ...

  10. 网站出现502 bad getway

    最近项目之余,领导叫解决下系统网站经常出现502的问题,作为小头头的我,怎能不顶上. 流程开始走起,先查nginx,嗯,配置是大众的.是不是缓存溢出了呢.调节buffer的值 .貌似也没什么影响啊.5 ...