# poj 3207 Ikki's Story IV - Panda's Trick

（1）将每条link看做两个点，分别表示在圆内链接和在圆外链接，只能选一个，用i和i表示。

选择j，i必选

选择i，j必选

选择j，i必选

// poj 3207 Ikki's Story IV - Panda's Trick
// ole 1656K 32MS
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define FOR(i,a,b) for(i = (a); i < (b); ++i)
#define FORE(i,a,b) for(i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(i = (a); i > (b); --i)
#define FORDE(i,a,b) for(i = (a); i >= (b); --i)
#define CLR(a,b) memset(a,b,sizeof(a))
#define PB(x) push_back(x)

const int MAXN = 1100;
const int MAXM = 500 * 500 * 4 + 2;
bool in_stack[MAXN];
int num, cnt, m, n, cnt_num;
int step[MAXN];
int low[MAXN];
int belong[MAXN];
int g[MAXN][2];
stack<int> st;
struct edge{
int v, nxt;
}e[MAXM];

void addedge(int u, int v) {
e[cnt].v = v;
}

void Tarjan(int u) {
int v;
int i,j;

step[u] = low[u] = ++num;
st.push(u);
in_stack[u] = true;
for(i = head[u]; i != -1; i = e[i].nxt){
v = e[i].v;
if(!step[v]){
Tarjan(v);
low[u] = min(low[u],low[v]);
}
else if(in_stack[v])
low[u] = min(low[u],step[v]);
}
if(step[u] == low[u]){
cnt_num++;
do{
j = st.top();
st.pop();
in_stack[j] = false;
belong[j] = cnt_num;
}while(j != u);
}
}

void init() {
int i, j;

CLR(belong, 0);
CLR(g, 0);
CLR(step, 0);
CLR(low, 0);
CLR(in_stack, false);
cnt = num = cnt_num = 0;
FORE(i, 1, m) {
scanf("%d %d", &g[i][0], &g[i][1]);
if(g[i][0] > g[i][1])
swap(g[i][0], g[i][1]);
}
FORE(i, 1, m - 1) FORE(j, i + 1, m) {
if(g[i][0] < g[j][0] && g[j][0] < g[i][1] && g[i][1] < g[j][1] ||
g[j][0] < g[i][0] && g[i][0] < g[j][1] && g[j][1] < g[i][1]) {
}
}
}

void solve() {
int i;

FORE(i, 1, 2 * m) if(step[i] == 0)
Tarjan(i);
FORE(i, 1, m)
if(belong[i] == belong[i + m])
break;
(i <= m) ? printf("the evil panda is lying again\n") : printf("panda is telling the truth...\n");
}

int main() {
while(scanf("%d %d", &n, &m) != EOF) {
init();
solve();
}
return 0;
}



01-22 99

08-10 559

07-15 78

10-08 315

08-08 169

07-09 16

09-19 474

10-26 722

05-17 749