Ikki's Story IV - Panda's Trick
Time Limit: 1000MS   Memory Limit: 131072K
Total Submissions: 10238   Accepted: 3762

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

将边看成点,然后拆点,一个代表圆内边(以点代边),一个代表园外边.
由约束条件搞出哪些点在所建图中必定要相连,然后跑tajan得到联通块‘
并查集也是可以的 平面上,一个圆,圆的边上按顺时针放着n个点。现在要连m条边,比如a,b,那么a到b可以从圆的内部连接,也可以从圆的外部连接。给你的信息中,每个点最多只会连接的一条边。问能不能连接这m条边,使这些边都不相交。 2-sat中一条有向边的涵义是选了起点就必须选终点
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
const int M=;
const int INF=;
int n,m,tot,head[N];
int dfn[N],low[N],index,instack[N],scc;
int top,st[N],fa[N];
int x[N],y[N];
struct edge{
int v,nxt;
}e[M];
void init(){
tot=index=scc=top=;
memset(dfn,,sizeof(dfn));
memset(instack,,sizeof(instack));
memset(head,-,sizeof(head));
}
void insert(int x,int y){
e[tot].v=y;
e[tot].nxt=head[x];
head[x]=tot++;
}
void Tarjan(int u){
instack[u]=;
st[top++]=u;
dfn[u]=low[u]=++index;
for(int i=head[u];~i;i=e[i].nxt){
int v=e[i].v;
if(!dfn[v]) {
Tarjan(v);
low[u]=min(low[u],low[v]);
}
else if(instack[v]) low[u]=min(low[u],dfn[v]);
}
if(dfn[u]==low[u]){
++scc;int t;
do{
t=st[--top];
instack[t]=;
fa[t]=scc;
}while(t!=u);
}
}
void build(){
for(int i=;i<=m;++i){
scanf("%d%d",&x[i],&y[i]);
++x[i],++y[i];
if(x[i]>y[i]) swap(x[i],y[i]);
}
for(int i=;i<=m;++i) for(int j=i+;j<=m;++j)
if((x[i]<=x[j]&&y[i]>=x[j]&&y[i]<=y[j])||(x[i]>=x[j]&&x[i]<=y[j]&&y[i]>=y[j])){
insert(i,j+m);
insert(j,i+m);
insert(i+m,j);
insert(j+m,i);
}
n=*m;
}
bool check(){
for(int i=;i<=m;++i) if(fa[i]==fa[i+m]) return false;
return true;
}
void solve(){
for(int i=;i<=n;++i) if(!dfn[i]) Tarjan(i);
if(check()) puts("panda is telling the truth...");
else puts("the evil panda is lying again");
}
int main(){
scanf("%d%d",&n,&m);
init();
build();
solve();
}

2-SAT poj3207将边看做点的更多相关文章

  1. 学习笔记(two sat)

    关于two sat算法 两篇很好的论文由对称性解2-SAT问题(伍昱), 赵爽 2-sat解法浅析(pdf). 一些题目的题解 poj 3207 poj 3678 poj 3683 poj 3648 ...

  2. 多边形碰撞 -- SAT方法

    检测凸多边形碰撞的一种简单的方法是SAT(Separating Axis Theorem),即分离轴定理. 原理:将多边形投影到一条向量上,看这两个多边形的投影是否重叠.如果不重叠,则认为这两个多边形 ...

  3. [Effective JavaScript 笔记]第54条:将undefined看做“没有值”

    undefined值很特殊,每当js无法提供具体的值时,就会产生undefined. undefined值场景 未赋值的变量的初始值即为undefined. var x; x;//undefined ...

  4. POJ 3678 Katu Puzzle(2 - SAT) - from lanshui_Yang

    Description Katu Puzzle is presented as a directed graph G(V, E) with each edge e(a, b) labeled by a ...

  5. poj3207

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

  6. Map Labeler POJ - 2296(2 - sat 具体关系建边)

    题意: 给出n个点  让求这n个点所能建成的正方形的最大边长,要求不覆盖,且这n个点在正方形上或下边的中点位置 解析: 当然是二分,但建图就有点还行..比较难想..行吧...我太垃圾... 2 - s ...

  7. LA 3211 飞机调度(2—SAT)

    https://vjudge.net/problem/UVALive-3211 题意: 有n架飞机需要着陆,每架飞机都可以选择“早着陆”和“晚着陆”两种方式之一,且必须选择一种,第i架飞机的早着陆时间 ...

  8. hdu1695 GCD 莫比乌斯反演做法+枚举除法的取值 (5,7),(7,5)看做同一对

    /** 题目:hdu1695 GCD 链接:http://acm.hdu.edu.cn/status.php 题意:对于给出的 n 个询问,每次求有多少个数对 (x,y) , 满足 a ≤ x ≤ b ...

  9. 2016-2017 ACM-ICPC CHINA-Final H Great Cells ans[i]*i看做整体,转化为期望理解来解题

    /** 题目:2016-2017 ACM-ICPC CHINA-Final H Great Cells 链接:http://codeforces.com/gym/101194 题意:给定n*m的矩形, ...

随机推荐

  1. opencv-10-图像滤波-噪声添加与均值滤波-含opencv C++ 代码实现

    开始之前 再说上一篇文章中, 我们想按照噪声产生, 然后将降噪的, 但是限于篇幅, 我就放在这一篇里面了, 说起图像的噪声问题就又回到了我们上一章的内容, 把噪声当作信号处理, 实际上数字图像处理实际 ...

  2. 【Linux常见命令】tr命令

    tr - translate or delete characters tr 命令用于转换或删除文件中的字符. tr 指令从标准输入设备读取数据,经过字符串转译后,将结果输出到标准输出设备. 语法: ...

  3. shell脚本(多线程批量创建用户)

    shell脚本中的多线程 很多场景中会用到多线程,例如备份数据库,有100个库,正常备份效率极其低下.有了多线程原本可能需要10个小时备份,现在分10个线程同时去干,只要一个小时就解决了.今天就介绍下 ...

  4. 用三维的视角理解二维世界:完美解释meshgrid函数,三维曲面,等高线,看完你就懂了。...

    完美解释meshgrid函数,三维曲面,等高线 #用三维的视角理解二维世界 #完美解释meshgrid函数,三维曲面,等高线 import numpy as np import matplotlib. ...

  5. Node.js中的express框架,修改内容后自动更新(免重启),express热更新

    个人网站 https://iiter.cn 程序员导航站 开业啦,欢迎各位观众姥爷赏脸参观,如有意见或建议希望能够不吝赐教! 以前node中的express框架,每次修改代码之后,都需要重新npm s ...

  6. SVN签出,回退

    2019独角兽企业重金招聘Python工程师标准>>> yum install -y subversion 安装SVN 签出代码 : [root@test svn]# svn che ...

  7. SaltStack数据系统之Grains、Pillar

    SaltStack数据系统之Grains.Pillar 1.什么是Grains? Grains是saltstack的组件,用于收集salt-minion在启动时候的信息,又称为静态信息.Grains是 ...

  8. uiautomatorviewer 出现安卓8.0级以上无法打开的解决方法

    一..本人在使用Android自带的uiautomatorviewer工具来进行app元素定位时,出现了Android 9.0打开不了.出现了如下图错误提示: 经过网上的查阅,总结了几个解决的方法. ...

  9. QT入门指导

    罗列一些QT学习资料 1. http://www.qter.org/ 包含很多教程,包括著名的<学习之路>系列. 2. http://www.qtcn.org/bbs/index-htm- ...

  10. thinkphp历史漏洞

    https://github.com/pochubs/pochubs/blob/master/ThinkPHP.md tp 历史漏洞 路由控制類RCE/think/App.php if (!preg_ ...