_bzoj1001 [BeiJing2006] wolf Scratch Rabbit "Floor plan"

Source: Internet
Author: User

Portal: http://www.lydsy.com/JudgeOnline/problem.php?id=1001

By the way recommend a PPT, there is a description of the floor plan: analysis of the maximum minimum theorem in the application of the information contest.

Here directly to the minimum cut must be T, so should be the original image as a floor plan, PPT said that the plane map corresponding to each of the dual map of the original one cut, which some do not understand, but do not affect this problem. Imagine, in the outermost of the infinite plane, from the upper left corner to the lower right corner with an additional edge, so do more an additional surface, set this additional edge of the weight of-inf, then the minimum cut must contain this edge. By removing this edge, it becomes a problem of finding the shortest path.

#include <cstdio> #include <cstring>const int maxn = 1005, maxnd = MAXN * MAXN << 1, maxe = MAXN * MAXN * 3;int N, M, S, T, special = 2147483647, T1, T2, T3;int head[maxnd], to[maxe << 1], next[maxe << 1], W[maxe &L t;< 1], Lb;char ch;bool inq[maxnd];int que[maxnd], H, head_, tail, d[maxnd];inline void ist (int aa, int ss, int ww) {to [lb] = ss;next[lb] = Head[aa];head[aa] = lb;w[lb] = ww;++lb;}  inline void readint (int & RT) {while ((ch = getchar ()) <), RT = Ch-48;while ((ch = getchar ()) > +) {rt = RT * ten + ch-48;}} int main (void) {//freopen ("In.txt", "R", stdin), memset (head,-1, sizeof head), memset (Next,-1, sizeof next), Readint (n); r Eadint (m); if (n = = 1 | | m = = 1) {while (scanf ("%d", &t1)! = EOF) {special = Special < T1? Special:t1;} printf ("%d\n", special); return 0;} S = (n-1) * (m-1) * 2 + 1;  T = S + 1;for (int i = 1; I <= n; ++i) {for (int j = 1; j < m; ++j) {t2 = (i-1) * (m-1) * 2 + J * 2;t1 = T2-(m -1) * 2-1;T1 = T1 > 0? T1:t;t2 = T2 < S? T2:S;SCANF ("%d", &t3), ist (t1, T2, T3), ist (T2, T1, T3);}}  for (int i = 1; i < n; ++i) {t2 = (i-1) * (m-1) * 2 + 1;scanf ("%d", &t3), ist (S, t2, T3), ist (T2, S, T3), and for (int j = 2; J < M; ++J) {t1 = (i-1) * (m-1) * 2 + (j-1) * 2;t2 = t1 + 1;scanf ("%d", &t3), ist (t1, T2, T3), ist (T2, T1, T3); T1 = i * (m-1) * 2;SCANF ("%d", &t3), ist (t1, T, T3), ist (t, T1, T3);}  for (int i = 1; i < n; ++i) {for (int j = 1; j < m; ++j) {t2 = (i-1) * (m-1) * 2 + J * 2;t1 = t2-1;scanf ("%d", &AMP;T3), ist (t1, T2, T3), ist (T2, T1, T3);}} memset (d, 0x3c, sizeof D); que[tail++] = s;inq[s] = True;d[s] = 0;while (head_! = tail) {h = que[head_++];if (Head_ = = T) { Head_ = 0;} INQ[H] = false;for (int j = head[h]; J! =-1; j = Next[j]) {if (D[to[j]] > D[h] + w[j]) {D[to[j]] = D[h] + w[j];if (!in Q[TO[J]]) {Inq[to[j]] = true;que[tail++] = to[j];if (tail = = T) {tail = 0;}}}} printf ("%d\n", D[t]); return 0;}

  

_bzoj1001 [BeiJing2006] wolf Scratch Rabbit "Floor plan"

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.