Time Limit: 1000MS | Memory Limit: 131072K | |
Total Submissions: 9278 | Accepted: 3416 |
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 <cstdlib>
#include <cstring>
#include <cmath>
#include <stack>
#include <bitset>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#define Si(a) scanf("%d",&a)
#define Sl(a) scanf("%lld",&a)
#define Sd(a) scanf("%lf",&a)
#define Ss(a) scanf("%s",a)
#define Pi(a) printf("%d\n",(a))
#define Pl(a) printf("%lld\n",(a))
#define Pd(a) printf("%lf\n",(a))
#define Ps(a) printf("%s\n",(a))
#define W(a) while(a--)
#define mem(a,b) memset(a,(b),sizeof(a))
#define FOP freopen("data.txt","r",stdin)
#define inf 0x3f3f3f3f
#define maxn 1010
#define mod 1000000007
#define PI acos(-1.0)
#define LL long long
using namespace std;
bool visit[maxn];
vector<vector<int > >adj;//原图
vector<vector<int > >radj;//逆图
int id[maxn],order[maxn];//强连通分量,访问顺序
int n,cnt;
struct Node
{
int l,r;
}node[maxn];
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;
int i,len=radj[u].size();
id[u]=cnt;
for(i=0;i<len;i++)
{
if(!visit[radj[u][i]])
rdfs(radj[u][i]);
}
}
void korasaju()
{
int i;
mem(visit,false);
for(cnt=0,i=0;i<2*n;i++)
if(!visit[i])
dfs(i);
mem(id,0);
mem(visit,false);
for(cnt=0,i=2*n-1;i>=0;i--)
{
if(!visit[order[i]])
{
cnt++;
rdfs(order[i]);
}
}
}
int solve()
{
int i;
for(i=0;i<n;i++)
{
if(id[2*i]==id[2*i+1])
return 0;
}
return 1;
}
int main()
{
int i,j,N,x,y;
while(~scanf("%d%d",&N,&n))
{
for(i=0;i<n;i++)
{
Si(x),Si(y);
if(x>y)swap(x,y);
node[i].l=x;
node[i].r=y;
}
adj.assign(2*n,vector<int>());//void assign(size_type n,const T& x = T());
radj.assign(2*n,vector<int>()); //赋n个值为x的元素到vector容器中,这个
//容器会清除掉vector容器中以前的内容
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if((node[i].l<node[j].l&&node[i].r>node[j].l&&node[i].r<node[j].r)||
(node[j].l<node[i].l&&node[j].r>node[i].l&&node[j].r<node[i].r))
{
adj[2*i].push_back(2*j+1);
adj[2*j+1].push_back(2*i);
adj[2*j].push_back(2*i+1);
adj[2*i+1].push_back(2*j);
radj[2*i].push_back(2*j+1);
radj[2*j+1].push_back(2*i);
radj[2*j].push_back(2*i+1);
radj[2*i+1].push_back(2*j);
}
}
}
korasaju();
if(solve())Ps("panda is telling the truth...");
else Ps("the evil panda is lying again");
}
return 0;
}