Time Limit: 1000MS Memory Limit: 131072K
Total Submissions: 9426 Accepted: 3465

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

 
又是WA在数组不够大←
 
连接两个点的一段线,要么全部在圆里,要么全部在圆外
先在各段线之间连边:若是两段线可能有交叉,那么必须一个在圆里,一个在圆外
建好图后用tarjan求强连通分量,若是表示一段线在圆里和圆外的两个点在同一个强连通分量里,那么就不可行
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int mxn=;
//bas
int n,m;
int hd[mxn],cnt=;
int a[mxn],b[mxn]; //edge
struct edge{
int to;
int next;
}e[mxn];
void add_edge(int u,int v){
e[++cnt].next=hd[u];e[cnt].to=v;hd[u]=cnt;
} //tarjan
int vis[mxn];
int dfn[mxn],low[mxn];
int st[mxn],top;
bool inst[mxn];
int dtime=;
int belone[mxn],tot;
void tarjan(int s){
low[s]=dfn[s]=++dtime;
st[++top]=s;
inst[s]=;
for(int i=hd[s];i;i=e[i].next){
int v=e[i].to;
if(!dfn[v]){
tarjan(v);
low[s]=min(low[s],low[v]);
}
else if(inst[v]){
low[s]=min(low[s],dfn[v]);
}
}
int v;
if(low[s]==dfn[s]){
cnt++;
do{
v=st[top--];
inst[v]=;
belone[v]=cnt; }while(v!=s);
}
return;
} //
void Build(){
int i,j;
for(i=;i<m;i++)
for(j=i+;j<=m;j++){
if((a[i]<a[j] && a[j]<b[i] && b[i]<b[j]) ||
(a[i]>a[j] && a[i]<b[j] && b[i]>b[j]) ){
add_edge(i,j+m);//用+m的点表示在外面
add_edge(j,i+m);
add_edge(i+m,j);
add_edge(j+m,i); }
}
return;
}
int main(){
scanf("%d%d",&n,&m);
int i,j;
for(i=;i<=m;i++){
scanf("%d%d",&a[i],&b[i]);
a[i]++;b[i]++;
if(a[i]>b[i])swap(a[i],b[i]);
}
Build();
n=*m;
for(i=;i<=n;i++)if(!dfn[i])tarjan(i);
for(i=;i<=m;i++){
if(belone[i]==belone[i+m]){
printf("the evil panda is lying again");
return ;
}
}
printf("panda is telling the truth...");
return ;
}
05-11 11:25