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();
}

最新文章

  1. OData的初步认识
  2. EF7 Code First Only-所引发的一些“臆想”
  3. [转]Google Guava官方教程(中文版)
  4. 将DLL中资源导出到指定文件夹
  5. 用refresh控制浏览器定时刷新
  6. 服务器保持与Mysql的连接
  7. linux下svn的co如何排除目录
  8. Load an X509 PEM file into Windows CryptoApi
  9. php学习笔记4--php中的变量作用域
  10. MongoDB自定义函数部分 定义及引用
  11. linux c coding style
  12. Repeater 模板中查找子控件
  13. Vue中应用CORS实现AJAX跨域,及它在 form data 和 request payload 的小坑处理
  14. MongoDB系列五(地理空间索引与查询).
  15. nltk分词
  16. 51 NOd 1459 迷宫游戏 (最短路径)
  17. Day 07 字符编码,文件操作
  18. git 项目配置用户名、邮箱的方法
  19. silverlight导出图片文件
  20. 【MySQL】 Cannot load from mysql.proc. The table is probably corrupted

热门文章

  1. Linux指令面试题01-进程查看与终止
  2. 在CentOS 7中安装配置JDK8
  3. stl的stack在开发中的应用
  4. Codeforce 1098-A
  5. js世家委托详解
  6. python(while 循环语句)
  7. Git上传本地仓库项目到gitee远程仓库(命令篇)
  8. 跟哥一起学python(2)- 运行第一个python程序&amp;环境搭建
  9. B. Sorted Adjacent Differences(思维构造)
  10. 测试开发专题:spring-boot统一异常捕获