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. linux下使用Android studio启动模拟器时提示 waiting for target device to come online 的问题

    方法来自:http://stackoverflow.com/questions/42612468/how-can-i-get-more-information-about-waiting-for-ta ...

  2. Python FLask 腾讯云服务器部署

    CentOs 7.0云服务器部署Python Flask 使用: Python 2.7 Flask nginx gunicorn easy_install python-dev yum install ...

  3. NOSQL:redis mongodb

    redis 1 概念及其基本操作:http://blog.nosqlfan.com/html/3139.html 2 安装配置及其操作:http://blog.fens.me/linux-redis- ...

  4. 一个关于C++拷贝构造的bug

    #include <iostream> using namespace std; class A { public: A(int a) {}; A(const A&) = defa ...

  5. java并发的一些杂乱小结

    1.java语言本身就提供了多线程机制,这样即使在单任务的操作系统上也可以实现多线程,这也是java语言本身"编写一次,到处运行"的特性. 2.并发要解决的问题本质上是:多个线程同 ...

  6. Python3与2的故事一

    print函数:(Python3中print为一个函数,必须用括号括起来:Python2中print为class) Python 2 的 print 声明已经被 print() 函数取代了,这意味着我 ...

  7. 安装oracle执行runInstaller文件时报错:“……/install/.oui:Permission denied”

    一:问题描述 二:出错原因 将windows下未解压的Oracle安装软件上传到了linux服务器,导致有三个文件的执行权限丢失. 三:解决方法 为其赋予相应权限即可. 1: [root@MyPc ~ ...

  8. day25-3 json,pickle模块

    目录 json 序列化 反序列化 pickle json json文件并不是python独有的,所有的语言都有json,可以跨平台/语言传输数据 json文件中只能写入python中的dict/lis ...

  9. C#学习 第六节

    什么是类型(Type)? 类型在C#中的作用 C#语言的类型系统 变量.对象与内存 类型(Type):数据类型 性质相同的值得集合:内存:内部存储单元,计算机运行程序的空间:外存:扩展存储器,硬盘: ...

  10. NGUI学习随笔

    一.NGUI的直接用法 1.      Attach a Collider:表示为NGUI的某些物体添加碰撞器,如果界面是用NGUI做的,只能这样添加.(注:用Component添加无效). 2.  ...