主题

主题

 
   

Ikki's Story IV - Panda's Trick

原题:http://poj.org/problem?id=3207

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


题目大意:

给出一个圆,圆上有n个点,按顺序编号。给出m条边,每条边可以从圆内经过,也可以从圆外经过。求是否存在一种方案,使得所有的边都不相交。


个人解法:

刚开始准备拿点对建虚点。日常算错复杂度,RE+TLE……

后来想到似乎可以直接拿边来建虚点。思路差不多,每条边拆为“圆内”与“圆外”两个点。

本来打算2-sat。不过这个题目告诉我们,如果是双向边的话,可以直接用并查集。


代码如下:

https://code.csdn.net/snippets/2278483

 
 
评论