POJ 3207 2-sat
来源:互联网 发布:mac上用的无线鼠标 编辑:程序博客网 时间:2024/04/27 22:38
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 andm (n ≤ 1,000, m ≤ 500). The following m lines each contain two integersai and bi, which denote the endpoints of theith 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 20 13 2
Sample Output
panda is telling the truth...
Source
#include<stdio.h>#include<algorithm>#include<stack>#include<vector>using namespace std;struct line{int s;int t;};vector<int>map[1005];int belong[1005],dfn[1005],low[1005];bool instack[1005],used[1005];stack<int>s;int index,cnt,n,m;line l[505];void init(){int i;for(i=0;i<1005;i++)map[i].clear();memset(dfn,-1,sizeof(dfn));memset(used,0,sizeof(used));memset(low,0,sizeof(low));memset(belong,0,sizeof(belong));memset(instack,0,sizeof(instack));index=0;cnt=0;}int min(int a,int b){if(a>b)return b;elsereturn a;}void tarjan(int u){int i,v;index++;dfn[u]=index;low[u]=index;instack[u]=true;s.push(u);used[u]=true;for(i=0;i<map[u].size();i++){v=map[u][i];if(!used[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]){cnt++;do{v=s.top();s.pop();belong[v]=cnt;instack[v]=false;}while(u!=v);}}int main(){int i,j;init();scanf("%d%d",&n,&m);for(i=1;i<=m;i++){scanf("%d%d",&l[i].s,&l[i].t);if(l[i].s>l[i].t)swap(l[i].s,l[i].t);}for(i=1;i<=m;i++)for(j=1;j<=m;j++)if((l[i].t<l[j].t&&l[i].s<l[j].s&&l[i].t>l[j].s)||(l[i].t>l[j].t&&l[i].s>l[j].s&&l[i].s<l[j].t)){map[i].push_back(j+m);map[i+m].push_back(j);map[j].push_back(i+m);map[j+m].push_back(i);}for(i=1;i<=2*m;i++){if(dfn[i]==-1)tarjan(i);}for(i=1;i<=m;i++){if(belong[i]==belong[i+m]){printf("the evil panda is lying again/n");return 0;}}printf("panda is telling the truth.../n");return 0;}
- POJ 3207 2-sat
- poj 3207 2-sat
- 【2-SAT】POJ 3207
- POJ 3207 2-SAT
- poj 3207 2-sat
- poj 3207 2-SAT
- POJ 3207 2-SAT
- POJ 3207 2-sat
- poj 3207(2-sat判断)
- POJ 3207 2SAT入门
- POJ-3207(2-SAT)
- poj 3207(2-SAT)
- 2-SAT ( Tarjan )——POJ 3207
- 2-sat POJ 3678
- poj 3683【2-SAT】
- 【2-SAT】POJ 3648
- 【2-SAT】POJ 3678
- POJ 3678 2-sat
- 系统研究Java--容器(五)--部分容器的底层实现
- BCB开发可Dockable的工具栏和视窗
- 女性英文名大全
- JAVA反射机制定义
- Javascript在jsp页面的使用(一)
- POJ 3207 2-sat
- SAP ABAP 学习路线图
- live555库
- 2 Texture && PRVShell
- 安装Android SDK时出错解决
- 男生英文名大全
- java的addShutdownHook
- 互加好友 有积分送 兄弟帮忙啊
- 泛型入门