HDU 4888 Redraw Beautiful drawings (maximum flow, sentence ring)

Source: Internet
Author: User

http://acm.hdu.edu.cn/showproblem.php?pid=4888


Add a source point and a sink point, and build the following example :

1.   Span style= "LINE-HEIGHT:22PX; font-size:11pt; Font-family: Italic "> source point   Span style= "LINE-HEIGHT:22PX; font-size:11pt; font-family: ">->" in italics;   Span style= "LINE-HEIGHT:22PX; font-size:11pt; Font-family: Italic "> The corresponding point in each row, the traffic is limited to the line and the

2. the corresponding points in each line  - Each column corresponds to a point where the traffic is limited to K

3.   Span style= "LINE-HEIGHT:22PX; font-size:11pt; Font-family: Italic "> corresponding point of each column   Span style= "LINE-HEIGHT:22PX; font-size:11pt; font-family: ">->" in italics;   Span style= "LINE-HEIGHT:22PX; font-size:11pt; Font-family: Italic "> meeting point, flow limit for this column and

To find the maximum flow, if the maximum flow is equal to the sum of the matrix, it shows that there is a solution, otherwise there is no solution. The inferred unique solution is to infer whether there is a ring with a length greater than 2 in the residual network. If there is a description of how many solutions, otherwise there is a unique solution, the solution is each side row i-> column J traffic.


#include <stdio.h> #include <iostream> #include <map> #include <set> #include <stack># Include <vector> #include <math.h> #include <string.h> #include <queue> #include <string> #include <stdlib.h> #include <algorithm> #define LL long long#define _ll __int64#define eps 1e-12#define PI aco S ( -1.0) #define C 240#define S 20using namespace std;const int INF = 0x3f3f3f3f;const int MAXN = 810;const int MAXM = 16000 0+810;struct node{int u,v,w,next;} edge[maxm << 1];int cnt,head[maxn];int n,m,k,s,t;int nn[410],mm[410];int maxf    Low;int vis[maxn];int dis[maxn];void init () {cnt = 0; memset (head,-1,sizeof (Head));}    void Add (int u, int v, int f) {edge[cnt] = (struct node) {U,v,f,head[u]};    Head[u] = cnt++;    EDGE[CNT] = (struct node) {v,u,0,head[v]}; HEAD[V] = cnt++;}    BOOL BFs () {queue<int>que;    while (!que.empty ()) Que.pop ();    memset (dis,-1,sizeof (dis));    Dis[s] = 0;    Que.push (s);   while (!que.empty ()) {int u = que.front ();        Que.pop ();            for (int i = head[u]; i =-1; i = edge[i].next) {int v = EDGE[I].V;                if (dis[v] = =-1 && edge[i].w) {dis[v] = dis[u]+1;            Que.push (v);    }}} if (dis[t] = = 1) return false; return true;}    int dfs (int u, int delta) {if (U = = T | | delta = = 0) return delta;    int DD;    int ret = 0; for (int i = head[u]; I! =-1 && delta; i = edge[i].next) {if (dis[edge[i].v] = = dis[u]+1 && (dd            = DFS (Edge[i].v,min (DELTA,EDGE[I].W)))) {EDGE[I].W-= DD;            EDGE[I^1].W + = DD;            Delta-= DD;            RET + = DD;        if (delta = = 0) return ret; }}dis[u] = -1;return ret;}    int dinic () {int ret = 0;    while (BFS ()) {ret + = DFS (s,inf); } return ret;} int dfs_1 (int u,int fa) {for (int i=head[u]; i!=-1; i=edge[i].next) {if (i== (FA^1)) continue;            if (EDGE[I].W) {if (VIS[EDGE[I].V]) return 1;            Vis[edge[i].v]=1;            if (Dfs_1 (edge[i].v,i)) return 1;        vis[edge[i].v]=0; }} return 0;} void Putmat () {int f[410][410];p rintf ("unique\n"), for (int u = 1, u <= n; u++) {for (int i = head[u]; I! =-1; i = Edge[i]. Next) {int v = edge[i].v;if (V > N && v <= n+m) f[u][v-n] = K-EDGE[I].W;}} for (int i = 1; I <= n; i++) {for (int j = 1; j < M; j + +) printf ("%d", F[i][j]);p rintf ("%d\n", F[i][m]);}}        int main () {while (~SCANF ("%d%d%d", &n,&m,&k)) {init ();        s = 0;        t = n+m+1;        int sum1 = 0;        int sum2 = 0;            for (int i = 1; I <= n; i++) {scanf ("%d", &nn[i]);            Add (S,i,nn[i]);        Sum1 + = nn[i];for (int j = 1; j <= M; j + +) Add (i,j+n,k);            } for (int i = 1; I <= m; i++) {scanf ("%d", &mm[i]);            Add (I+n,t,mm[i]); Sum2 + = Mm[i];        } if (sum1! = sum2) {printf ("impossible\n"); }else{maxflow = Dinic (); if (maxflow! = sum1) {printf ("impossible\n");} Else{int flag = 0;memset (vis,0,sizeof (VIS)), for (int i = 1; I <= n; i++) {if (Dfs_1 (i,-1)) {flag = 1;break;}}    if (flag = = 1) printf ("Not unique\n"); Elseputmat ();}} } return 0;}





HDU 4888 Redraw Beautiful drawings (maximum flow, sentence ring)

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.