Time Limit: 1000MS | Memory Limit: 131072KB | 64bit IO Format: %I64d & %I64u |
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<stdio.h> #include<string.h> #include<queue> #include<stack> #include<algorithm> using namespace std; #define MAX 100000+10 int low[MAX],dfn[MAX]; int sccno[MAX]; int scc_cnt,dfs_clock,cnt; bool Instack[MAX]; int m,n,num1[MAX],num2[MAX]; vector<int>G[MAX]; stack<int>s; struct node { int u,v; int next; }edge[MAX*2]; void init() { for(int i=1;i<=3*m;i++) G[i].clear(); } bool judge(int a, int b, int c, int d) { return (c > a && b > c && d > b) || (a > c && d > a && b > d); } void getmap() { for(int i=1;i<=m;i++) scanf("%d%d",&edge[i].u,&edge[i].v); for(int i=1;i<=m;i++) { for(int j=1;j<i;j++) {//如果会相交的话 if(judge(edge[i].u,edge[i].v,edge[j].u,edge[j].v)) { G[i+2*m].push_back(j+m);//i边j边在里在外,四种情况 G[i+m].push_back(j+2*m); G[j+m].push_back(i+2*m); G[j+2*m].push_back(i+m); } } } } void tarjan(int u,int fa) { int v; low[u]=dfn[u]=++dfs_clock; s.push(u); Instack[u]=true; for(int i=0;i<G[u].size();i++) { v=G[u][i]; if(!dfn[v]) { tarjan(v,u); low[u]=min(low[v],low[u]); } else if(Instack[v]) low[u]=min(low[u],dfn[v]); } if(low[u]==dfn[u]) { ++scc_cnt; for(;;) { v=s.top(); s.pop(); Instack[v]=false; sccno[v]=scc_cnt; if(v==u) break; } } } void find(int l,int r) { memset(Instack,false,sizeof(Instack)); memset(sccno,0,sizeof(sccno)); memset(dfn,0,sizeof(dfn)); memset(low,0,sizeof(low)); scc_cnt=dfs_clock=0; for(int i=l;i<=r;i++) if(!dfn[i]) tarjan(i,-1); } void solve() { int flog=1; for(int i=1;i<=m;i++) { if(sccno[i+m]==sccno[i+2*m]) { flog=0; printf("the evil panda is lying again "); break; } } if(flog) printf("panda is telling the truth... "); } int main() { scanf("%d%d",&n,&m); init(); getmap(); find(1,3*n); solve(); return 0; }