Time Limit: 1000MS   Memory Limit: 131072K
Total Submissions: 9426   Accepted: 3465

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

 
又是WA在数组不够大←
 
连接两个点的一段线,要么全部在圆里,要么全部在圆外
先在各段线之间连边:若是两段线可能有交叉,那么必须一个在圆里,一个在圆外
建好图后用tarjan求强连通分量,若是表示一段线在圆里和圆外的两个点在同一个强连通分量里,那么就不可行
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int mxn=;
//bas
int n,m;
int hd[mxn],cnt=;
int a[mxn],b[mxn]; //edge
struct edge{
int to;
int next;
}e[mxn];
void add_edge(int u,int v){
e[++cnt].next=hd[u];e[cnt].to=v;hd[u]=cnt;
} //tarjan
int vis[mxn];
int dfn[mxn],low[mxn];
int st[mxn],top;
bool inst[mxn];
int dtime=;
int belone[mxn],tot;
void tarjan(int s){
low[s]=dfn[s]=++dtime;
st[++top]=s;
inst[s]=;
for(int i=hd[s];i;i=e[i].next){
int v=e[i].to;
if(!dfn[v]){
tarjan(v);
low[s]=min(low[s],low[v]);
}
else if(inst[v]){
low[s]=min(low[s],dfn[v]);
}
}
int v;
if(low[s]==dfn[s]){
cnt++;
do{
v=st[top--];
inst[v]=;
belone[v]=cnt; }while(v!=s);
}
return;
} //
void Build(){
int i,j;
for(i=;i<m;i++)
for(j=i+;j<=m;j++){
if((a[i]<a[j] && a[j]<b[i] && b[i]<b[j]) ||
(a[i]>a[j] && a[i]<b[j] && b[i]>b[j]) ){
add_edge(i,j+m);//用+m的点表示在外面
add_edge(j,i+m);
add_edge(i+m,j);
add_edge(j+m,i); }
}
return;
}
int main(){
scanf("%d%d",&n,&m);
int i,j;
for(i=;i<=m;i++){
scanf("%d%d",&a[i],&b[i]);
a[i]++;b[i]++;
if(a[i]>b[i])swap(a[i],b[i]);
}
Build();
n=*m;
for(i=;i<=n;i++)if(!dfn[i])tarjan(i);
for(i=;i<=m;i++){
if(belone[i]==belone[i+m]){
printf("the evil panda is lying again");
return ;
}
}
printf("panda is telling the truth...");
return ;
}

POJ3207 Ikki's Story IV – Panda's Trick的更多相关文章

  1. POJ3207 Ikki's Story IV - Panda's Trick 【2-sat】

    题目 liympanda, one of Ikki's friend, likes playing games with Ikki. Today after minesweeping with Ikk ...

  2. poj3207 Ikki’s Story IV – Panda’s Trick

    2-SAT. tarjan缩点.强连通分量的点要选一起选. #include<cstdio> #include<algorithm> #include<cstring&g ...

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

    题目链接:http://poj.org/problem?id=3207 题意:在一个圆圈上有n个点,现在用线把点两两连接起来,线只能在圈外或者圈内,现给出m个限制,第 i 个点和第 j 个点必须链接在 ...

  4. poj3207 Ikki's Story IV - Panda's Trick 2-SAT

    题目传送门 题意:在一个圆上顺时针安放着n个点,给出m条线段连接端点,要求线段不相交,线段可以在圆内也可以在圆外,问是否可以. 思路:假设一条线段,放在圆外是A,放在园内是A',那么两条线段如果必须一 ...

  5. poj3207 Ikki's Story IV - Panda's Trick 2-sat问题

    ---题面--- 题意:给定一个圈,m条边(给定),边可以通过外面连,也可以通过里面连,问连完这m条边后,是否可以做到边两两不相交 题解: 将连里面和连外面分别当做一种决策(即每条边都是决策点), 如 ...

  6. 【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 ...

  7. 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 ...

  8. 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   ...

  9. 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 ...

随机推荐

  1. 【PHP项目】伪静态规则

    伪静态规则写法RewriteRule-htaccess详细语法使用 2016年03月30日 16:53:59 阅读数:20340 伪静态实际上是利用php把当前地址解析成另一种方法来访问网站,要学伪静 ...

  2. POJ:2236-Wireless Network

    Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 34265 Accepted: 14222 D ...

  3. Unity Occlusion Culling 遮挡剔除研究

    本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接:http://blog.csdn.net/cartzhang/article/details/52684127 作者:car ...

  4. Spring---bean的实例化

    Spring IoC容器如何实例化Bean呢?传统应用程序可以通过new和反射方式进行实例化Bean.而Spring IoC 容器则需要根据Bean定义里的配置元数据使用反射机制来创建Bean.在Sp ...

  5. P2285 [HNOI2004]打鼹鼠

    P2285 [HNOI2004]打鼹鼠 题目描述 鼹鼠是一种很喜欢挖洞的动物,但每过一定的时间,它还是喜欢把头探出到地面上来透透气的.根据这个特点阿牛编写了一个打鼹鼠的游戏:在一个n*n的网格中,在某 ...

  6. Android stadio 模板 liveTemplate不管用

    今天自己弄了模板,发现不生效.后来才知道要在下面设置在哪里应用:如下图: Android satdio 制作自己的todo 有时候,别人都使用todo,使得自己个人的todo不好用了.那么怎么弄?自己 ...

  7. nodejs基础1

    nodejs学习网站: https://github.com/alsotang/node-lessons 1.全局对象 (1)node中没有window对象,有global对象替代window对象 g ...

  8. SDWebImage实现原理(怎么实现图片缓存器)

    入口 setImageWithURL:placeholderImage:options: 会先把 placeholderImage 显示,然后 SDWebImageManager 根据 URL 开始处 ...

  9. ios开发3.5和4.0寸屏幕自适应中的一点问题

    在开发iso应用中需要考虑到ip4的3.5寸屏幕和ip5的4寸屏幕的高度不一样的问题.常见的问题有滚动条位置,底部被挡住等情况:我遇见是tableview中添加下拉上提刷新功能时刷新指示器显示位置的问 ...

  10. 修改window 10 开始菜单问题

    cmd->powershell Get-AppxPackage | % { Add-AppxPackage -DisableDevelopmentMode -Register "$($ ...