码迷,mamicode.com
首页 > 其他好文 > 详细

(2 sat) poj 3207

时间:2015-04-19 19:18:04      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

Ikki‘s Story IV - Panda‘s Trick
Time Limit: 1000MS   Memory Limit: 131072K
Total Submissions: 8437   Accepted: 3101

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

Source

 
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<set>
#include<stack>
using namespace std;
vector<int> mp[2010];
stack<int> s;
int n,m;
int Dfs[2010],low[2010],use[2010],isstack[2010];
int newflag,top;
struct node
{
    int x,y;
}e[100010];
bool check(int a,int b,int c,int d)
{
    if((c>a&&b>c&&d>b)||(a>c&&d>a&&b>d))
        return true;
    return false;
}
void init()
{
    memset(Dfs,0,sizeof(Dfs));
    memset(low,0,sizeof(low));
    memset(use,0,sizeof(use));
    memset(isstack,0,sizeof(isstack));
    top=0;
    newflag=0;
    while(!s.empty())
        s.pop();
}
void tarjan(int u)
{
    Dfs[u]=low[u]=++top;
    isstack[u]=1;
    s.push(u);
    for(int i=0;i<mp[u].size();i++)
    {
        int v=mp[u][i];
        if(!Dfs[v])
        {
            tarjan(v);
            low[u]=min(low[u],low[v]);
        }
        else if(isstack[v])
        {
            low[u]=min(low[u],Dfs[v]);
        }
    }
    if(low[u]==Dfs[u])
    {
        newflag++;
        int x;
        do
        {
            x=s.top();
            s.pop();
            isstack[x]=0;
            use[x]=newflag;
        }while(x!=u);
    }
}
int main()
{
    init();
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&e[i].x,&e[i].y);
        if(e[i].x>e[i].y)
            swap(e[i].x,e[i].y);
    }
    for(int i=1;i<=2*m+1;i++)
        mp[i].clear();
    for(int i=1;i<=m;i++)
    {
        for(int j=i+1;j<=m;j++)
        {
            if(check(e[i].x,e[i].y,e[j].x,e[j].y))
            {
                mp[2*i].push_back(2*j+1);
                mp[2*i+1].push_back(2*j);
                mp[2*j+1].push_back(2*i);
                mp[2*j].push_back(2*i+1);
            }
        }
    }
    for(int i=1;i<=2*m+1;i++)
    {
        if(!Dfs[i])
            tarjan(i);
    }
    bool flag=true;
    for(int i=1;i<=m;i++)
    {
        if(use[2*i]==use[2*i+1])
        {
            flag=0;
            break;
        }
    }
    if(flag)
    {
        printf("panda is telling the truth...\n");
    }
    else
        printf("the evil panda is lying again\n");
    return 0;
}

  

(2 sat) poj 3207

标签:

原文地址:http://www.cnblogs.com/a972290869/p/4439549.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!