Ikki's Story IV - Panda's Trick
Time Limit: 1000MS Memory Limit: 131072K
Total Submissions: 7296 Accepted: 2705

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 a and b, 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

 
   2-sat ,点为线段。
#include <iostream>
#include <stdio.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <stack>
#include <math.h>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#pragma comment(linker, "/STACK:10240000000000,10240000000000")
using namespace std;
typedef long long LL ;
const int Max_N= ;
const int Max_M= ;
int id ;
int vec[Max_N] ,mystack[Max_N] ,top;
int low[Max_N] ,dfn[Max_N] ,idx ,num ;
bool instack[Max_N] ;
int belong[Max_N] ; //belong[i] ,i为哪个联通分量
//int sum[Max_N] ; //缩点后每个联通分量中点的个数
struct Edge{
int v ;
int next ;
};
Edge edge[Max_M] ;
inline void add_edge(int u,int v){
edge[id].v=v ;
edge[id].next=vec[u] ;
vec[u]=id++ ;
}
void tarjan(int u){
low[u]=dfn[u]=idx++ ;
mystack[++top]=u ;
instack[u]= ;
for(int e=vec[u];e!=-;e=edge[e].next){
int v=edge[e].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(low[u]==dfn[u]){
int v ;
num++ ;
do{
v=mystack[top--] ;
instack[v]= ;
belong[v]=num ;
// sum[num]++ ;
}while(v!=u) ;
}
}
void init(){
idx= ;
top=- ;
num= ;
id=;
memset(dfn,-,sizeof(dfn)) ;
memset(vec,-,sizeof(vec)) ;
memset(instack,,sizeof(instack)) ;
// memset(sum,0,sizeof(sum)) ;
}
int N ;
int judge(){
for(int i=;i<=N;i++){
if(belong[i]==belong[i+N])
return ;
}
return ;
}
struct Line{
int s ;
int t ;
};
Line L[Max_N] ;
int cross(Line A ,Line B){
if(B.s<A.s&&A.s<B.t&&B.t<A.t)
return ;
if(A.s<B.s&&B.s<A.t&&A.t<B.t)
return ;
return ;
}
int main(){
int m ;
while(scanf("%d%d",&m,&N)!=EOF){
for(int i=;i<=N;i++)
scanf("%d%d",&L[i].s,&L[i].t) ;
init() ;
for(int i=;i<=N;i++)
for(int j=i+;j<=N;j++){
if(cross(L[i],L[j])){
add_edge(i,j+N) ;
add_edge(j,i+N) ;
add_edge(i+N,j) ;
add_edge(j+N,i) ;
}
}
for(int i=;i<=*N;i++){
if(dfn[i]==-)
tarjan(i) ;
}
if(judge())
puts("panda is telling the truth...") ;
else
puts("the evil panda is lying again") ;
}
return ;
}
04-27 17:16