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


POJ Monthly--2007.03.04, Ikki


n个点顺时针排在圆环上,有m条边,现在问你所有边不相交是不是可能,其中这些边可以是往圆环外建,也可以是圆环内建

可以证明,当两条边不可能同时在圆环内建时,也不可能在圆环外建,这样我们把在圆环内建边看成i,圆环外建边看成i‘ ,这样这个问题就是典型的2-sat适定性问题了

在这里学的2-sat,讲的真的很好啊, 点击打开链接

刚刚接触2-sat,还是不熟悉啊、、、、

#include<map>
#include<set>
#include<list>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>

using namespace std;

const int N=251000;

struct node
{
	int to;
	int next;
}edge[N];
int head[N];
int DFN[N],low[N];
int tot,index,sccnum,Top,m;
int stack[N];
bool instack[N];
int block[N];

struct point
{
	int x,y;
}List[N];

void addedge(int from,int to)
{
	edge[tot].to=to;
	edge[tot].next=head[from];
	head[from]=tot++;
}

void tarjan(int u,int fa)
{
	DFN[u]=low[u]=++index;
	instack[u]=1;
	stack[Top++]=u;
	for(int i=head[u];i!=-1;i=edge[i].next)
	{
		int v=edge[i].to;
		if(v==fa)
			continue;
		if(!instack[v])
		{
			tarjan(v,u);
			low[u]=min(low[u],low[v]);
		}
		else
			low[u]=min(low[u],DFN[v]);
	}
	if(low[u]==DFN[u])
	{
		sccnum++;
		do
		{
			Top--;
			instack[Top]=0;
			block[stack[Top]]=sccnum;
		}while(u!=stack[Top]);
	}
}

void solve()
{
	memset(low,0,sizeof(low));
	memset(DFN,0,sizeof(DFN));
	memset(block,0,sizeof(block));
	memset(instack,0,sizeof(instack));
	sccnum=0;
	index=0;
	Top=0;
	bool flag=false;
	for(int i=1;i<=2*m;i++)
		if(!DFN[i])
			tarjan(i,-1);
	for(int i=1;i<=2*m;i+=2)
		if(block[i]==block[i+1])
		{
			flag=true;
			break;
		}
	if(flag)
		printf("the evil panda is lying again\n");
	else
		printf("panda is telling the truth...\n");
}

int main()
{
	int n;
	while(~scanf("%d%d",&n,&m))
	{
		memset(head,-1,sizeof(head));
		tot=0;
		for(int i=1;i<=m;i++)
		{
			scanf("%d%d",&List[i].x,&List[i].y);
			if(List[i].x > List[i].y)
			{
				List[i].x^=List[i].y;
				List[i].y^=List[i].x;
				List[i].x^=List[i].y;
			}
		}
		for(int i=1;i<=m;i++)
			for(int j=i+1;j<=m;j++)
			{
				if(List[i].x < List[j].x && List[i].y < List[i].y && List[i].x<List[j].y)
				{
					addedge(2*i-1,2*j);
					addedge(2*j-1,2*i);
					addedge(2*j,2*i-1);
					addedge(2*i,2*j-1);
				}
				else if(List[j].x < List[i].x && List[j].y < List[i].y && List[j].x < List[i].y)
				{
					addedge(2*i-1,2*j);
					addedge(2*j-1,2*i);
					addedge(2*j,2*i-1);
					addedge(2*i,2*j-1);
				}
			}
		solve();
	}
	return 0;
}