2014多校3(1002)hdu4888(最大流(dinic))

来源:互联网 发布:去掉数组中重复的元素 编辑:程序博客网 时间:2024/06/05 11:17

Redraw Beautiful Drawings

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2213    Accepted Submission(s): 495


Problem Description
Alice and Bob are playing together. Alice is crazy about art and she has visited many museums around the world. She has a good memory and she can remember all drawings she has seen.

Today Alice designs a game using these drawings in her memory. First, she matches K+1 colors appears in the picture to K+1 different integers(from 0 to K). After that, she slices the drawing into grids and there are N rows and M columns. Each grid has an integer on it(from 0 to K) representing the color on the corresponding position in the original drawing. Alice wants to share the wonderful drawings with Bob and she tells Bob the size of the drawing, the number of different colors, and the sum of integers on each row and each column. Bob has to redraw the drawing with Alice's information. Unfortunately, somtimes, the information Alice offers is wrong because of Alice's poor math. And sometimes, Bob can work out multiple different drawings using the information Alice provides. Bob gets confused and he needs your help. You have to tell Bob if Alice's information is right and if her information is right you should also tell Bob whether he can get a unique drawing.
 

Input
The input contains mutiple testcases.

For each testcase, the first line contains three integers N(1 ≤ N ≤ 400) , M(1 ≤ M ≤ 400) and K(1 ≤ K ≤ 40).
N integers are given in the second line representing the sum of N rows.
M integers are given in the third line representing the sum of M columns.

The input is terminated by EOF.
 

Output
For each testcase, if there is no solution for Bob, output "Impossible" in one line(without the quotation mark); if there is only one solution for Bob, output "Unique" in one line(without the quotation mark) and output an N * M matrix in the following N lines representing Bob's unique solution; if there are many ways for Bob to redraw the drawing, output "Not Unique" in one line(without the quotation mark).
 

Sample Input
2 2 44 24 2 4 2 22 2 5 05 41 4 391 2 3 3
 

Sample Output
Not UniqueImpossibleUnique1 2 3 3

题意:给出一个矩阵,输入n,m代表矩阵的行和列,然后是n个数代表每行的数的总和,然后是m个数代表每列的总和

求:给矩阵每个位置填数,要求输入的每行和每列的总和都满足

思路:很容易想到网络流,重点在建图,首先从源点向每行的节点连边,流量为该行的总和,然后每行的节点向每列的节点连边,流量为K,最后是每列的节点向汇点连边,流

量为每列的总和,然后求最大流,满流就是有解,然后题目还要求在有解的情况下要判断是否有多解,这个只用在残留网络中用DFS找环即可,存在环则有多解,因为可以通过

环来改变各条边的流量,还有就是注意建图的时候要边输入边建图,不然就会TL,被这个坑了好久= =

0 0
原创粉丝点击