Poj 2289 binary maximum stream

Source: Internet
Author: User

This type of question has been done in two ways, so you will know the Train of Thought as soon as you see the question. However, the input of this question is disgusting, and it is better to cope with it.

I didn't want to do this, but I saw 1500 more data points. I wanted to try it with a linked list. I first typed a two-dimensional array and waited for 1y in the Process of TLE ....

It hurts! 1500 MS is not fast...

# Include <iostream> # include <cstdio> # include <cstdlib> # include <string> # include <map> # define CC (a) memset (A, 0, sizeof (A) # define ff (I, A) for (INT I = 0; I <A; I ++) # define Mn 1555 # define me 555555 template <class T> void inline checkmin (T & A, t B) {if (a =-1 | A> B) A = B;} using namespace STD; struct edge {int V, C, next;} e [Me]; int N, NE, M, S, T, can; int head [Mn], gap [Mn], pre [Me], DIS [Mn], cur [Mn]; int maze [Mn] [Mn], cap [Mn] [m N]; void setg () {CC (CAP); Map <string, int> map; string STR; int num; char C; S = 0; t = n + m + 1; FF (I, n) {CIN> STR; Map [STR] = m + I + 1; num =-1; // people: [M + 1, m + n] list: [1, m] While (scanf ("% C", & C )) {If (C = ''| C = '\ n') {If (num =-1) continue; else CAP [num + 1] [map [STR] ++; If (C = '\ n') break; num =-1 ;} else {If (num =-1) num = C-'0'; else num = num * 10 + C-'0 ';}}} for (INT I = m + 1; I <= m + n; I ++) CAP [I] [T] = 1;} void initg (INT mid) {for (INT I = 0; I <= T; I ++) for (Int J = 0; j <= T; j ++) maze [I] [J] = CAP [I] [J]; for (INT I = 1; I <= m; I ++) maze [s] [I] = mid;} bool SAP () {CC (cur); CC (GAP); CC (pre); CC (DIS ); int u = pre [s] = s, maxflow = 0, Aug =-1; Gap [0] = t + 1; while (DIS [s] <= T) {loop: For (INT v = cur [u]; v <= T; V ++) if (maze [u] [v] & dis [u] = dis [v] + 1) {pre [v] = u; cur [u] = V; checkmin (Aug, maze [u] [v]); U = V; If (V = T) {maxflow ++ = Aug; For (u = pre [u]; v! = S; V = u, u = pre [u]) {maze [u] [v]-= Aug; maze [v] [u] + = Aug ;} aug =-1;} goto loop;} int mind = t; for (int v = 0; v <= T; V ++) if (maze [u] [v] & mind> dis [v]) {cur [u] = V; mind = dis [v];} if (-- gap [dis [u] = 0) break; Gap [dis [u] = mind + 1] ++; u = pre [u];} if (maxflow = N) return true; else return false;} int main () {While (scanf ("% d", & N, & M )! = EOF) {If (n = 0 & M = 0) break; setg (); int L = 1, R = n, m; while (M = (L + r)/2) & L <r) {initg (m); If (SAP () r = m; else l = m + 1;} printf ("% d \ n", m);} 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.