# POJ 3207 Ikki’s Story IV – Panda’s Trick （2-SAT）

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


2-SAT 问题

## AC 代码

#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
using namespace std;
typedef __int64 LL;

const int maxn = 1e6+10;

class TwoSAT
{
public:
struct node
{
int to;
int next;
} edge[maxn];
bool vis[maxn];         // 染色标记 true 表示选择
int S[maxn],top;        // 栈

void init(int n)
{
tot = 0;
this->n = n;
}

{
edge[tot].to = v;
}

bool dfs(int x)
{
if(vis[x^1])return false;
if(vis[x])return true;
vis[x] = true;
S[top++] = x;
if(!dfs(edge[i].to))
return false;
return true;
}

bool solve()
{
memset(vis,false,sizeof(vis));
for(int i=0; i<n; i+=2)
{
if(vis[i]||vis[i^1])continue;
top = 0;
if(!dfs(i))
{
while(top)
vis[S[--top]] = false;
if(!dfs(i^1))return false;
}
}
return true;
}
} sat;

typedef pair<int,int> P;
vector<P> cnt;
int main()
{
int n,m;
while(cin>>n>>m)
{
cnt.clear();
for(int i=0; i<m; i++)
{
int u,v;
cin>>u>>v;
if(u>v)swap(u,v);
cnt.push_back(P(u,v));
}
sat.init(2*m);
for(int i=0; i<m; i++)
{
for(int j=i+1; j<m; j++)
{
if((cnt[i].first<cnt[j].second&&cnt[i].first>cnt[j].first&&cnt[i].second>cnt[j].second)||(cnt[i].second<cnt[j].second&&cnt[i].second>cnt[j].first&&cnt[i].first<cnt[j].first))
{
int xx = i*2;
int yy = j*2;