ZOJ1157, Poj1087,uva 753 A Plug for UNIX (Max Stream)

Source: Internet
Author: User
Tags mul

Links: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26746

The topic meaning is a bit difficult to describe with a person described well.




My map method: One source point, one sink point, and all kinds of sockets. The n sockets are connected directly to the source point, the capacity is the number of items per outlet in the 1,m item input, and the number of items greater than 0 is connected directly to the meeting point, which means that the final item can only be drained from these outlets. The middle of the socket conversion capacity is INF a B means that no matter how many B can choose to convert to a.


/*---------------------#headfile--------------------*/#include <algorithm> #include <iostream># Include <sstream> #include <cstring> #include <cstdlib> #include <cassert> #include <cstdio > #include <vector> #include <cmath> #include <queue> #include <stack> #include <set># Include <map>/*----------------------#define----------------------*/#define DRII (x, y), scanf ("%d% D ",& (X),& (Y)) #define EXP 2.7182818284590452353602874713527#define caset int _;cin>>_;while (_--) # Define RII (x, Y) scanf ("%d%d",& (x),& (Y)) #define DRI (x) int (x), scanf ("%d", &x) #define MEM (A, B) memset (A, B, sizeof (a)) #define REP (I,n) for (int. i=0;i<n;i++) #define ALL (x) (x). Begin (), (x). End () #define INFL 0x3f3f3f3f3f3f3f3fll#define RI (x) scanf ("%d",& (x)) #define SZ (x) ((int) x.size ()) #define PDI Pair<double,int > #define Rson o<<1|1,m+1,r#define PII pair<int,int> #define MAX 0x3f3f3f3f#define Lson o<<1, L,m#define MP make_pair#define PB push_back#define SE second#define FI firsttypedef Long Long ll;template<class T>T MUL (t x,t y,t P) {t f1=0;while (y) {if (y&1) {f1+=x;if (f1<0| | f1>=p) f1-=p;} X<<=1;if (x<0| | x>=p) X-=p;y>>=1;} return F1;} Template<class t>t POW (t x,t y,t P) {t f1=1;x%=p;while (y) {if (y&1) F1=mul (f1,x,p); X=mul (x,x,p); y>>=1;} return F1;} Template<class t>t gcd (T x,t y) {if (y==0) return x; T z;while (z=x%y) X=y,y=z;return y;} #define DRIII (x, y), (z), scanf ("%d%d%d",& (x),& (y),& (z)) #define RIII, X, Z, scanf ("%d%d%d", & (X),& (Y),& (Z)) const double PI = ACOs ( -1.0); const double EPS = 1e-6;const ll mod = 1000000007ll;const int M =  1005;const int N = 605;using namespace std;/*----------------------Main-------------------------*/struct Edge {int to,    C, Rev;    Edge () {} edge (int _to, int _c, int _rev) {to = _to, C = _c, rev = _rev; }};vector<edge> G[n];int Lv[n], iter[n];int N, M;void BFS (inT s) {mem (LV,-1);    Queue<int> Q;    Lv[s] = 0;    Q.push (s);        while (!q.empty ()) {int v = q.front (); Q.pop ();            for (int i = 0; i < SZ (G[v]); i++) {Edge &e = g[v][i];                if (e.c > 0 && lv[e.to] < 0) {lv[e.to] = Lv[v] + 1;            Q.push (e.to);    }}}}int dfs (int v, int t, int f) {if (v = = t) return F;        for (int &i = iter[v]; I < SZ (G[v]); i++) {Edge &e = g[v][i];            if (e.c > 0 && lv[v] < lv[e.to]) {int d = DFS (e.to, T, Min (f, e.c));                if (d > 0) {e.c-= D;                G[E.TO][E.REV].C + = D;            return D; }}} return 0;}    int MF (int s, int t) {int res = 0; for (;;)        {BFS (s);        if (Lv[t] < 0) return res;        MEM (ITER, 0);        int F;        while ((f = DFS (S, T, 1e9)) > 0) {res + = f; }}}void Add (int from, int. to,int c) {G[from].    PB (Edge (To, C, SZ (g[to))); G[to]. PB (Edge (from, 0, SZ (G[from])-1));} int Num[n];int FF = 0;void Solve () {if (FF) puts ("");    FF = 1;    RI (n);    for (int i = 0; i <; i++) g[i].clear ();    MEM (num, 0);    int s = 0, k = 0;    Map<string, int> vis;        for (int i = 1; I <= n; i++) {string S1; Cin >> S1;        VIS[S1] = ++k;    Add (S, I, 1);    } RI (M);        for (int i = 1; I <= m; i++) {string S1, S2;        CIN >> S1 >> S2;        if (vis[s2] = = 0) vis[s2] = ++k;    num[Vis[s2]]++;    } int t = k + 1;    for (int i = 1; I <= K; i++) {if (Num[i]) Add (i, T, Num[i]);    } DRI (x);    k++;        for (int i = 1; i <= x; i++) {string S1, S2;        CIN >> S1 >> S2;        if (vis[s2] = = 0) vis[s2] = ++k;        if (vis[s1] = = 0) vis[s1] = ++k;        int u = vis[s2], v = vis[s1];    Add (U, V, 1e9);    } int ans = MF (s, t); printf ("%d\n", M-ans);}  int main () {//  Freopen ("In.txt", "R", stdin);//Freopen ("OUT.txt", "w", stdout);    Caset solve (); return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

ZOJ1157, Poj1087,uva 753 A Plug for UNIX (Max Stream)

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.