您的位置:首页 > 其它

poj3207 Ikki's Story IV - Panda's Trick 2011-12-26

2016-03-02 20:17 162 查看
Ikki's Story IV - Panda's TrickTime Limit: 1000MSMemory Limit: 131072KTotal Submissions: 4996Accepted: 1843

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 20 13 2

Sample Output

panda is telling the truth...

Source

POJ Monthly--2007.03.04, Ikki _______________________________________

Program Stone;
var i,j,k,l,le,deep,n,m,o:longint;
a,b:array[1..500]of longint;
head,next,date,tr:array[1..1000000]of longint;
stack,dfn,low:array[1..1000000]of longint;
v,f:array[1..1000000]of boolean;
procedure add(x,y:longint);
begin
inc(le);
date[le]:=y;
next[le]:=head[x];
head[x]:=le;
end;
function check(x,y,z:longint):boolean;
begin
if (x>y)and(x<z) then check:=true
else check:=false;
end;
Procedure init;
var i,j,k:longint;
begin
readln(n,m);
for i:=1 to m do
begin
readln(a[i],b[i]);
if a[i]>b[i] then begin k:=a[i];a[i]:=b[i];b[i]:=k;end;
for j:=1 to i-1 do
if check(a[i],a[j],b[j])xor check(b[i],a[j],b[j]) then
begin
add(i,j+m);
add(j,i+m);
add(i+m,j);
add(j+m,i);
end;
end;
le:=0;
end;
procedure work(x:longint);
var i,j,k:longint;
begin
inc(o);
repeat
tr[stack[le]]:=o;               //染色
if stack[le]>m then i:=stack[le]-m else i:=stack[le]+m;
if tr[i]=o then begin           //如果冲突则无解
write('the evil panda is lying again');
halt;
end;
f[stack[le]]:=false;
dec(le);
until stack[le+1]=x;
end;
function min(a,b:longint):longint;
begin
if a<b then min:=a else min:=b;
end;
procedure tarjan(x:longint);
var i,j,k:longint;
begin
v[x]:=false;
inc(deep);
dfn[x]:=deep;
low[x]:=deep;
inc(le);
stack[le]:=x;
f[x]:=true;
i:=head[x];
while i<>0 do
begin
if v[date[i]] then
begin
tarjan(date[i]);
low[x]:=min(low[x],low[date[i]]);
end
else if f[date[i]] then low[x]:=min(low[x],dfn[date[i]]);
i:=next[i];
end;
if dfn[x]=low[x] then work(x);
end;
Begin
assign(input,'input.in');reset(input);
init;
fillchar(f,sizeof(f),false);
fillchar(v,sizeof(v),true);
for i:=1 to 2*m do
if v[i] then tarjan(i);
writeln('panda is telling the truth...');
end.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: