poj--3207--Ikki's Story IV - Panda's Trick(2-sat)
Time Limit: 1000MS | Memory Limit: 131072KB | 64bit IO Format: %I64d & %I64u |
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
#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;
}
最新文章
- 【Net跨平台第一步】逆天带你零基础Linux入门【更新完毕】
- [No00006C]文件名复制,归档小助手【自己写的小工具,希望能帮助大家】
- Java + 腾讯企业邮箱 + javamail + SSL 发送邮件
- IOS NSThread
- [转] TreeList 当前节点图标和背景色设置
- 腾讯云(centos)上安装apache
- light 1012 Guilty Prince
- ios开发使用lipo命令合并真机库和模拟器库
- JS判断doctype文档模式-document.compatMode
- PPT素才搜索简谈
- ORACLE数据库管理员的职责
- 【CF850E】Random Elections(FWT)
- python3+scrapy 趣头条爬虫实例
- (转)java调用python脚本
- [UE4]圆形小地图
- JAVA HW2
- Hadoop 2.4.1+HBase 0.98.6.1 分布式安装
- AJAX 与 Python 后台通信
- DPDK无法分出大页面:EAL: No free hugepages reported in hugepages-2048kB 解决方法
- 【AtCoder】ARC095 C-F题解