Poj 3207 Ikki's Story IV-panda's trick

Source: Internet
Author: User

The circle is marked from 0 to n-1 in turn, and m edges are given. When the m edges are connected, is there any intersection?

There are points in the garden ......


2-Sat


#include<iostream>#include<map>#include<string>#include<cstring>#include<cstdio>#include<cstdlib>#include<cmath>#include<queue>#include<vector>#include<algorithm>using namespace std;const int MAXN = 510;struct twosat{      int n,c;      vector<int> g[MAXN<<1];      bool mark[MAXN<<1];      int s[MAXN<<1];      bool dfs(int x) {  int i;        if (mark[x^1]) return 0;          if (mark[x]) return 1;          mark[x] = 1;          s[c++] = x;          for (i = 0; i < g[x].size(); i++)              if (!dfs(g[x][i])) return 0;          return 1;      }          void init(int n) {  int i,t=n<<1;        this->n = n;          for (i = 0; i < t; i++)               g[i].clear();          memset(mark, 0, sizeof(mark));      }        void add_clause(int x, int xval, int y, int yval) {          x = x * 2 + xval;          y = y * 2 + yval;          g[x^1].push_back(y);          g[y^1].push_back(x);      }        bool solve() {  int i,t=n<<1;        for (i = 0; i < t; i += 2)               if (!mark[i] && !mark[i + 1]) {                  c = 0;                  if (!dfs(i)) {                      while (c > 0) mark[s[--c]] =0;                       if (!dfs(i + 1)) return 0;                  }              }        return 1;      }  }ender;struct seg{int s,e;}in[510];bool iscross(seg a,seg b,int flag1,int flag2){if(flag1!=flag2)return 0;if(a.s<b.s&&b.s<a.e&&(b.e<a.s||b.e>a.e))return 1;if(b.s<a.s&&a.s<b.e&&(a.e<b.s||a.e>b.e))return 1;return 0;}int main(){int i,j,n,m,x,y;cin>>n>>m;for(i=0;i<m;i++){cin>>in[i].s>>in[i].e;if(in[i].s>in[i].e)swap(in[i].s,in[i].e);}ender.init(m);for(i=0;i<m;i++)for(j=i+1;j<m;j++)for(x=0;x<2;x++)for(y=0;y<2;y++)if(iscross(in[i],in[j],x,y))ender.add_clause(i,x,j,y);if(ender.solve())cout<<"panda is telling the truth..."<<endl;elsecout<<"the evil panda is lying again"<<endl;return 0;}

Ikki's Story IV-panda's trick
Time limit:1000 ms   Memory limit:131072 K
Total submissions:8142   Accepted:2993

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

Poj 3207 Ikki's Story IV-panda's trick

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.