POJ 3207 Ikki ' s Story Iv-panda ' s trick Classic modeling

Source: Internet
Author: User
Ikki ' s Story Iv-panda ' s trick
Time Limit: 1000MS Memory Limit: 131072K
Total submissions: 8729 accepted: 3224

Description

Liympanda, one of Ikki ' s friend, likes playing games with Ikki. Minesweeping with Ikki and winning so many times, the He is tired of such easy games and wants to play another GAM E 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 it is connecting m pairs of points. To connect two points, Liympanda either places the link entirely inside the circle or entirely the outside. Now Liympanda tells Ikki no two links to inside/outside the circle on the except. He wants Ikki to figure out whether the this is possible ...

Despaired at the minesweeping game just played, Ikki are totally at a loss, so his decides to write a.

Input

The input contains exactly one test case.

In the test case there'll be a line consisting 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 ith of the wire. Every Point would 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 ...


Just look at the 2-sat, there may be some places say wrong, welcome correction.


To give a circle, there are n dots (from 0 to n-1) on a circle, and now give you the M-line-A-point connected to point B (this line is either full in the circle or all outside the circle). Require that any two lines cannot intersect and that each point is up to one line, asking you to save a graphic that does not exist.


Transformation problem: Each edge can be outside the circle, or within the circle, which satisfies the 2-sat requirements of the two States. Therefore, we need to press the edge to handle, we set the AI as the first edge in the circle, bi for the first edge of the circle outside the round (the two are relative like true and false).


Train of thought: we assume that any two sides cannot intersect, so for the two lines that are likely to intersect, X and Y must have

(Ax extraction Ay) combined (Bx extract by) to really understand. The Boolean expression is equivalent to the collection of the following four expressions:

One: Ax-> by that x within the circle, Y does not intersect outside the circle

Two: Bx-> Ay that x in the circle, y in the circle will not intersect

Third: Ay-> Bx that y in the circle, Y will not intersect outside the circle

Four: by-> Ax that Y is outside the circle, X does not intersect within the circle

Judge two line intersection method, oneself in a circle draw a,b,c,d four points, respectively connect A->b c->d, see what conditions meet when intersect. I won't say it here.

For any possible intersection of both sides, the above processing is to build the edge.


My code starts with numbering 1, and the AI virtual as i + M on the edge of section I, the bi virtual into i + 2*m. After the map is Tarjan, there is an SCC to the graph,

Finally, enumerate all sides I (1-> m) to determine whether AI and bi are in the same SCC, and if a description exists on both sides of the intersection, the graph does not exist with the hypothetical contradiction.


AC Code:


#include <cstdio> #include <cstring> #include <vector> #include <queue> #include <stack> #
Include <algorithm> #define MAXN 4000 #define MAXM 500000 #define INF 10000000 using namespace std;
int n, m; 
struct Edge {int s, t;//beginning endpoint}num[maxm];//store each line vector<int> G[MAXN];
int LOW[MAXN], DFN[MAXN];
int dfs_clock;
int SCCNO[MAXN], scc_cnt;
Stack<int> S;
BOOL INSTACK[MAXN]; void Init () {for (int i = 1; I <= 3*m; i++) g[i].clear ();} bool Judge (int a, int b, int c, int d)//To determine whether to intersect {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", &num[i].s, &num[i].t); /* i + N table i +2*n (int i = 1; I <= m; i++) {for (int j = 1; j < I; J +) {if (Judge (Num[i].s, Num[i)  . T, Num[j].s, NUM[J].T)//intersect {g[i + 2*m].push_back (j + m);//i outside-> J G[i + m].push_back (j + 2*m);//i inside-> 
				Outside JG[j + m].push_back (i + 2*m);//j-> i outer g[j + 2*m].push_back (i + m);//j outside-> i}}} 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;
	Find_cut (int l, int r)//tarjan for SCC {memset (low, 0, sizeof (low));
	memset (DFN, 0, sizeof (DFN));
	memset (sccno, 0, sizeof (SCCNO));
	Memset (Instack, False, sizeof (Instack));
	Dfs_clock = scc_cnt = 0;
for (int i = l; I <= R; i++) if (!dfn[i]) Tarjan (i,-1);
	} void Solve () {bool flag = true;
			for (int i = 1; I <= m; i++) {if (sccno[i + m] = = Sccno[i + 2*m]) {flag = false;
			printf ("The Evil Panda is lying again\n");
		Break} if (flag) printf ("Panda is telling the truth...\n");
	int main () {scanf ("%d%d", &n, &m);
	Init ();
	Getmap ();
	Find_cut (1, 3*m);//EDGE processing the total number is 3*m solve ();
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.