POJ 3207 Ikki & #39; s Story IV, pojikki

Source: Internet
Author: User

POJ 3207 Ikki's Story IV, pojikki

Time Limit:1000 MS   Memory Limit:131072 K
Total Submissions:10870   Accepted:3988
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...

 

Question: There is a circle that shows some edges connected to two points. The edges can be connected from the circle or from outside the circle. Can they be separated?

 

For edge $ I, the j $ restriction condition is not intersection, that is, it is not in the same set

So we turn this issue into a 2-SAT question.

Set $ I $ to indicate the edge $ I $ inside the circle, $ I '$ to indicate $ I $ outside the circle

If the edge $ I and j $ intersect in the circle

From $ I $ to $ j '$, from $ j' $ to $ I $, from $ j $ to $ I '$, from $ I '$ to $ j $

Then, just repeat tarjan.

 

 

 

#include<cstdio>#include<cstring>#include<algorithm>#include<stack>#define Pair pair<int,int>#define F first#define S secondusing namespace std;const int MAXN=1e6+10;#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++)char buf[1<<20],*p1=buf,*p2=buf;inline int read(){    char c=getchar();int x=0,f=1;    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}    return x*f;}Pair p[MAXN];struct node{    int u,v,nxt;}edge[MAXN];int head[MAXN],num=1;inline void AddEdge(int x,int y){    edge[num].u=x;    edge[num].v=y;    edge[num].nxt=head[x];    head[x]=num++;}int dfn[MAXN],low[MAXN],vis[MAXN],color[MAXN],colornum=0,tot=0;stack<int>s;void tarjan(int now){    dfn[now]=low[now]=++tot;    s.push(now);    vis[now]=1;    for(int i=head[now];i!=-1;i=edge[i].nxt)    {        if(!dfn[edge[i].v])            tarjan(edge[i].v),low[now]=min(low[now],low[edge[i].v]);        if(vis[edge[i].v]) low[now]=min(low[now],dfn[edge[i].v]);    }    if(dfn[now]==low[now])    {        colornum++;        int h=0;        do        {            h=s.top();s.pop();            vis[h]=0;            color[h]=colornum;        }while(h!=now);    }}int main(){    #ifdef WIN32    freopen("a.in","r",stdin);    #else    #endif    memset(head,-1,sizeof(head));    int N=read(),M=read();    for(int i=1;i<=M;i++)    {        p[i].F=read(),p[i].S=read();        if(p[i].F>p[i].S) swap(p[i].F,p[i].S);    }    for(int i=1;i<=M;i++)    {        for(int j=i+1;j<=M;j++)        {            if((p[j].F>=p[i].F&&p[j].F<=p[i].S&&p[j].S>=p[i].S)||               (p[j].F<=p[i].F&&p[j].S>=p[i].F&&p[j].S<=p[i].S))               AddEdge(i,j+M),               AddEdge(j,i+M),               AddEdge(j+M,i),               AddEdge(i+M,j);        }    }    for(int i=1;i<=M;i++)        if(!dfn[i])            tarjan(i);    bool flag=1;    for(int i=1;i<=M;i++)        if(color[i]==color[i+M])            {printf("the evil panda is lying again\n");flag=0;break;}    if(flag==1) printf("panda is telling the truth...\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.