# [2-sat + binary] poj 2749

Source: Internet
Author: User

Http://hi.baidu.com/%8E%E1%D0%B3/blog/item/3f5354fa18498c01d9f9fd4a.html

`# Define n 1111 vector <int> V [N]; stack <int> S; bool vis [N]; bool instack [N]; int low [N], dfn [N]; int belong [N]; // The Strongly Connected Component int n, m, step, t, a, B; int Len; int SX [3], sy [3]; int A [1001] [2], B [1001] [2]; int d [N]; int DIS (INT X1, int Y1, int X2, int Y2) {return ABS (x1-x2) + ABS (y1-y2);} void Init () {int I; for (I = 0; I <= 2 * N; I ++) {v [I]. clear (); vis [I] = 0; instack [I] = 0;} while (! S. empty () s. pop ();} void add (int A, int B) {v [A]. push_back (B);} // Tarjan contraction point void Tarjan (INT U) {vis [u] = true; Step ++; S. push (U); instack [u] = true; low [u] = step, dfn [u] = step; int I, j; for (I = 0; I <V [u]. size (); I ++) {int x = V [u] [I]; If (! Vis [x]) {Tarjan (x); low [u] = min (low [u], low [x]);} else if (instack [x]) low [u] = min (low [u], dfn [x]);} If (low [u] = dfn [u]) {T ++; while (1) {int x = S. top (); S. pop (); belong [x] = T; instack [x] = false; If (x = u) Break ;}} void build (INT mid) {int I, j; Init (); int U, V; for (I = 1; I <= A; I ++) {u = A [I] [0]; V = A [I] [1]; add (u, v + n); add (v, U + n); add (U + N, V ); add (V + N, u) ;}for (I = 1; I <= B; I ++) {u = B [I] [0]; V = B [I] [1]; add (U, v); add (v, U); add (U + N, V + n); add (V + N, U + n );} for (I = 1; I <= N; I ++) {for (j = I + 1; j <= N; j ++) {If (d [I] + d [J]> mid) {Add (I, j + n); add (J, I + n );} if (d [I + N] + d [J + N]> mid) {Add (I + N, J); add (J + N, I );} if (d [I] + d [J + N] + Len> mid) {Add (I, j); add (J + N, I + n );} if (d [I + N] + d [J] + Len> mid) {Add (I + N, J + n); add (J, i) ;}}} bool sat (INT mid) {T = 0, step = 0; build (MID); int I; for (I = 1; I <= 2 * n; I ++) if (! Vis [I]) Tarjan (I); for (I = 1; I <= N; I ++) if (belong [I] = belong [I + N]) return false; return true;} int main () {While (scanf ("% d", & N, & A, & B )! =-1) {int I, j; scanf ("% d", & SX [1], & Sy [1], & SX [2], & Sy [2]); Len = DIS (SX [1], Sy [1], SX [2], Sy [2]); int L = 0, r = 0, mid; for (I = 1; I <= N; I ++) {int X, Y; scanf ("% d", & X, & Y); D [I] = DIS (X, Y, SX [1], Sy [1]); d [I + N] = DIS (X, Y, SX [2], Sy [2]); r = max (R, max (d [I], d [I + N]) ;}for (I = 1; I <= A; I ++) {// hate scanf ("% d ", & A [I] [0], & A [I] [1]) ;}for (I = 1; I <= B; I ++) {// Like scanf ("% d", & B [I] [0], & B [I] [1]);} int ans =-1; R * = 3; while (L <= r) {mid = (L + r)> 1; if (Sat (MID) {ans = mid; R = mid-1;} else l = Mid + 1;} printf ("% d \ n", ANS);} return 0 ;}`

Related Keywords:

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.