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

最新文章

  1. 【Net跨平台第一步】逆天带你零基础Linux入门【更新完毕】
  2. [No00006C]文件名复制,归档小助手【自己写的小工具,希望能帮助大家】
  3. Java + 腾讯企业邮箱 + javamail + SSL 发送邮件
  4. IOS NSThread
  5. [转] TreeList 当前节点图标和背景色设置
  6. 腾讯云(centos)上安装apache
  7. light 1012 Guilty Prince
  8. ios开发使用lipo命令合并真机库和模拟器库
  9. JS判断doctype文档模式-document.compatMode
  10. PPT素才搜索简谈
  11. ORACLE数据库管理员的职责
  12. 【CF850E】Random Elections(FWT)
  13. python3+scrapy 趣头条爬虫实例
  14. (转)java调用python脚本
  15. [UE4]圆形小地图
  16. JAVA HW2
  17. Hadoop 2.4.1+HBase 0.98.6.1 分布式安装
  18. AJAX 与 Python 后台通信
  19. DPDK无法分出大页面:EAL: No free hugepages reported in hugepages-2048kB 解决方法
  20. 【AtCoder】ARC095 C-F题解

热门文章

  1. B - Even Odds
  2. Hadoop MapReduce编程 API入门系列之wordcount版本5(九)
  3. Cupid&#39;s Arrow[HDU1756]
  4. R 连接DB2数据库,并制作词图
  5. 暴雪的hash算法[翻译]
  6. Robot Framework(四)创建测试套件
  7. JS 100元购物卡,牙刷5元,香皂2元、洗发水15元 100元正好花完有多少种可能
  8. 理解Faster-RCNN 中的Anchor
  9. JQ淡入淡出效果
  10. 重置浏览器默认样式 normalize.css