Poj 3207 Ikki's Story IV-panda's trick (2-Sat)

Source: Internet
Author: User
Ikki's Story IV-panda's trick
Time limit:1000 ms   Memory limit:131072 K
Total submissions:6065   Accepted:2234

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 areNPoints on its boundary in circular border: 0, 1, 2 ,...,N−1. edevil panda claims that he is ing 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, cycle T 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 two integers:NAndM(N≤ 1,000,M≤ 500). The followingMLines each contain two integersAIAndBi, Which denote the endpoints ofITh wire. Every point will have at most one link.

Output

Output a line, either"Panda is telling the truth..."Or"The edevil panda is lying again".

Sample Input

 
4 20 13 2

Sample output

 
Panda is telling the truth...

Source

Poj monthly -- 2007.03.04, Ikki is also a question about the feasibility of Question 2-sat. The template is ready after the image is created.
 /* Poj 3207: On the plane, there is a circle with N points clockwise on the side of the circle. To connect m edges, such as A and B, A to B can be connected from the inner of the circle or from the outer of the circle. In the information given to you, each vertex can only connect one edge at most. Ask if you can connect these m edges so that these edges do not overlap. Idea: For each link, either out of the circle or in the circle, and cannot meet the requirements at the same time, only one of the two can be taken to determine whether the M link is valid, that is, m links do not conflict, which is a typical 2-SAT problem. Consider each link I as a point. If the link is in the circle, select I. If it is out of the circle, select I '. For two wires (I, j), if I, j cannot be in the circle at the same time, it can be introduced that the two cannot be in the circle at the same time. This proof is easy and readers can prove it on their own. I, j cannot be in the circle at the same time, there are edges (I, j '), (J, I'), (I ', J), (j', I) (This is determined by the 2-Sat architecture. For details, refer to the paper "Solving 2-SAT problems by symmetry ). After the graph is created, this question is to determine whether the 2-SAT problem is resolved. First, find the strong connected component of the source image and reduce the point (here we call it: (I, I ') belongs to the same group ), determine whether (I, I ') exists in the same group. If yes, it is impossible. If no, it is possible. C ++ 204 Ms 2248 K  */  # Include <Stdio. h> # Include <Algorithm> # Include < String . H> # Include <Iostream> # Include <Math. h> # Include <Queue> # Include <Vector> Using   Namespace  STD;  Const   Int Maxn = 1010  ;  Bool  Visit [maxn]; queue < Int > Q1, Q2; //  The method for creating a vector graph is wonderful. Vector <vector < Int > Adj; //  Source image  //  Separate the two '>' with a space in the middle. Vector <vector < Int > Radj; //  Reverse Graph Vector <vector < Int > Dag; //  Reverse Dag after point reduction  Int N, CNT;  Int Id [maxn], order [maxn], IND [maxn]; //  Strongly connected components, access sequence, inbound  Void DFS ( Int  U) {visit [u] = True  ;  Int I, Len = Adj [u]. Size ();  For (I = 0 ; I <Len; I ++ ) If (! Visit [adj [u] [I]) DFS (adj [u] [I]); Order [CNT ++] = U ;}  Void RDFS ( Int  U) {visit [u] = True  ; Id [u] = CNT;  Int I, Len = Radj [u]. Size ();  For (I = 0 ; I <Len; I ++)  If (! Visit [radj [u] [I]) RDFS (radj [u] [I]);}  Void  Korasaju (){  Int  I; memset (visit,  False , Sizeof  (Visit ));  For (CNT = 0 , I = 0 ; I < 2 * N; I ++)  If (! Visit [I]) DFS (I); memset (ID,  0 , Sizeof  (ID); memset (visit,  False , Sizeof  (Visit ));  For (CNT = 0 , I = 2 * N- 1 ; I> = 0 ; I --)  If (! Visit [order [I]) {CNT ++; //  This must be put in front.  RDFS (Order [I]) ;}}  Bool  Solvable (){  For ( Int I = 0 ; I <n; I ++ )  If (ID [ 2 * I] = ID [2 * I + 1  ])  Return   False  ;  Return   True  ;}  Struct  Node {  Int  S, T;} node [maxn];  Int  Main (){  Int  N; Int  X, Y;  While (Scanf ( "  % D  " , & N, & N )! = EOF ){  For ( Int I = 0 ; I <n; I ++ ) {Scanf (  "  % D  " , & X ,&Y );  If (X> Y) Swap (x, y); node [I]. s = X; node [I]. t = Y;} adj. Assign (  2 * N, vector < Int > (); Radj. Assign (  2 * N, vector < Int > ());  For ( Int I =0 ; I <n; I ++ )  For ( Int J = I + 1 ; J <n; j ++ ){  If (Node [I]. S <node [J]. S & node [J]. S <node [I]. T & node [I]. T <node [J]. t) | (node [J]. S <node [I]. S & node [I]. S <node [J]. T & node [J]. T < Node [I]. t) {adj [  2 * I]. push_back ( 2 * J + 1 ); Adj [  2 * J + 1 ]. Push_back ( 2 * I); adj [  2 * I + 1 ]. Push_back ( 2 * J); adj [  2 * J]. push_back ( 2 * I + 1  ); Radj [  2 * J + 1 ]. Push_back ( 2 * I); radj [  2 * I]. push_back ( 2 * J + 1  ); Radj [  2 * J]. push_back ( 2 * I + 1  ); Radj [  2 * I + 1 ]. Push_back ( 2 * J) ;}} korasaju ();  If (Solvable () printf ( "  Panda is telling the truth... \ n  "  );  Else Printf ( "  The edevil panda is lying again \ n  "  );}  Return   0  ;} 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.