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. Python面向对象--高级(一)

    ## 属性的类型 - 属性可分为类属性和实例属性 - 实例属性可以通过在类中使用self定义,或者直接在类外部使用实例变量定义 class Person(object): def __init__(s ...

  2. Myeclipse上配置weblogic11g(10.3.6)的方法教程

    1.在windows-perferences-MyEclipse-Servers-weblogic下找到weblogic10.X 2.按照参考我上面的附图填入weblogic的相关路径(如果你是完全按 ...

  3. 2,Flask 中的 Render Redirect HttpResponse

    一,Flask中的HTTPResponse 在Flask 中的HttpResponse 在我们看来其实就是直接返回字符串 二,.Flask中的Redirect 每当访问"/redi" ...

  4. WCF入门二[WCF的配置文件]

    一.概述 往往在很多项目中数据库连接字符串.变量和一些动态的加载类会写在配置文件中.WCF也会在配置文件中写入一些配置参数,比如服务的地址.服务用于发送和接收消息的传输和消息编码等,通过配置文件可以灵 ...

  5. P1783 海滩防御

    P1783 海滩防御 题目描述 WLP同学最近迷上了一款网络联机对战游戏(终于知道为毛JOHNKRAM每天刷洛谷效率那么低了),但是他却为了这个游戏很苦恼,因为他在海边的造船厂和仓库总是被敌方派人偷袭 ...

  6. Android onConfigurationChanged 收不到回调

    我返现,90度横屏 旋转到270度横屏onConfigurationChanged 是收不到回掉的.尽管清单里面声明了什么: android:configChanges="orientati ...

  7. Retrofit get post query filed FiledMap

    直接请求型 1.如果是直接请求某一地址,写法如下: @GET("/record") Call getResult(); 2.如果是组合后直接请求,如/result/{id}写法如下 ...

  8. 一些 ssh 小技巧

    本文来自网易云社区. 作者:沈高峰 ssh 经常需要使用的,每次使用都  ssh  abc@XXX.def.com -p 12138 -i ~/.ssh/id_rsa 来一遍显然太麻烦了,下面分享一点 ...

  9. iOS笔记059 - 网络总结

    网络 基本概念 客户端:client 服务器:server 请求:request 响应:response 过程 客户端 -> 发送请求 -> 服务器(连接数据库) 服务器 -> 发送 ...

  10. android SharedPreferences 浅析

    1. 介绍:SharedPreferences 的作用是使用键值对的方式存储数据.且支持多种不同的数据类型存储: Android数据持久化方法中最简单的一种,即使用Preferences的键值对存储方 ...