ACM Computer Factory
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 5501 |
|
Accepted: 1887 |
|
Special Judge |
Description
As you know, all the computers used for ACM contests must is identical, so the participants compete on equal terms. That's why all these computers was historically produced at the same factory.
Every ACM computer consists of P parts. When all these parts was present, the computer is ready and can be shipped to one of the numerous ACM contests.
Computer manufacturing is fully automated by using N various machines. Removes some parts from a half-finished computer and adds some new parts (removing of parts are sometimes nece Ssary as the parts cannot is added to a computer in arbitrary order). Each machine was described by its performance (measured in computers per hour), input and output specification.
Input specification describes which parts must be present in a half-finished computer for the machine to being able to operat E on it. The specification is a set of P numbers 0, 1 or 2 (one number to each part), where 0 means tha T corresponding part must was present, 1-the part was required, 2-presence of the part doesn ' t matter.
Output specification describes the result of the operation, and is a set of P numbers 0 or 1, w Here 0 means of the part are absent, 1-the part is present.
The machines connected by very fast production lines so, delivery time is negligibly small compared to production Time.
After many years of operation the overall performance of the ACM computer Factory became insufficient for satisfying the G Rowing contest needs. That's why ACM Directorate decided to upgrade the factory.
As different machines were installed in different time periods, they were often not optimally connected to the existing FA Ctory machines. It was noted that the easiest-to upgrade the factory are to rearrange production lines. ACM Directorate decided to entrust and solving this problem.
Input
Input file contains integers P n, then n descriptions of The machines. The description of ith machine was represented as by 2 P + 1 integers Qi Si, 1 si, 2 ... Si,P di, 1 Di, 2 ... Di,P, where Qi Specifies performance, Si ,J -input Specification for part J, Di, K -output specification for part K.
Constraints
1 ≤ P ≤ 10, 1≤ N ≤ 50, 1≤ Qi ≤10000
Output
Output the maximum possible overall performance, then M -number of connections that must B E made, then M Descriptions of the connections. Each connection between machines A and B must be Described by three positive numbers A B W, where W is the number of computers delivered from A to B per hour.
If Several solutions exist, output any of them.
Sample Input
Sample Input 13 415 0 0 0 0 1 010 0 0 0 0 1 0 1 2 1 1 0 2, 1 1, 1 Sampl E Input 23 0 0 0 0 1 0100 0 1 0 1 0 0 1 0 1 1 1 0 1 1 1 0300 1 1 2 1 1 1Sample input 32 2100 0 0 1 0200 0 1 1 1
Sample Output
Sample Output 13 3sample Output 24, 3 5, 2, 4, 5 1Sample output 3 0 0
Hint
Bold texts appearing in the sample sections is informative and does not form part of the actual data. The first question seriously written, was __int64 pit. The main idea: assemble a computer, p components, n machines. 0 means there is no such component, 1 means there must be a component, and 2 means it can or may not. Requirements to find out what components are not from the initial computer, assembled into a complete computer of the most assembly line. Output assembly number, and machine connection mode. From all 0 as the source, all 1 is the sink point, each machine is split, and then connected to the diagram, and then Dinic.
#include <cstdio> #include <cstring> #include <algorithm> #include <queue>using namespace std;# Define INF 0x3f3f3f3f#define LL __int64struct node{int u, V, W; int next, K;} p[1000000];struct node1{int U, V, W;} q[1000000]; queue <int> que; LL in[110], out[110], num[110]; int head[110], cnt; int arr[110], vis[110]; void init () {cnt = 0; memset (In,0,sizeof (in)); Memset (out,0,sizeof (out)); memset (head,-1,sizeof (Head));} void Add (int u,int v,int w) {p[cnt].u = u; P[CNT].V = v; P[CNT].W = W; P[CNT].K = W; P[cnt].next = Head[u]; Head[u] = cnt++; p[cnt].u = v; P[CNT].V = u; P[CNT].W = 0; P[CNT].K = 0; P[cnt].next = Head[v]; HEAD[V] = cnt++;} BOOL Judge (LL x,ll y,int m) {int i, K1, K2; for (i = 1; I <= m; i++) {k1 = x% 10; K2 = y% 10; x/= 10; Y/= 10; if (k1 = = 2 | | k2 = = 2) continue; if (k1! = K2) return false; } return true; BOOL BFS (int s,int e) {int i, u, v; while (!que.empty ()) Que.pop (); memset (arr,-1,sizeof (arr)); Vis[s] = 1; Arr[s] = 0; Que.push (s); while (!que.empty ()) {u = Que.front (); Que.pop (); for (i = head[u]; I! =-1; i = p[i].next) {v = p[i].v; if (arr[v] = = 1 && p[i].w) {Arr[v] = Arr[u] + 1; Que.push (v); }}} if (Arr[e] > 0) return true; return false;} int dfs (int u,int t,int min1) {if (U = = t) return min1; int I, V, a, ans = 0; for (i = head[u]; I! =-1; i = p[i].next) {v = p[i].v; if (arr[v] = = Arr[u] + 1 && p[i].w && (a = DFS (V,t,min (MIN1,P[I].W)))) {P[I].W-= A P[I^1].W + = A; ans + = A; Min1-= A; if (!min1) break; } } if (ans) return ans; Arr[u] =-1; return 0;} int main () {int n, m, I, J, U, V, W, K, Max_flow, sum; while (scanf ("%d%d", &m, &n)! = EOF) {init (); Max_flow = sum = 0; for (i = 1; I <= n; i++) {k = 0; scanf ("%i64d", &num[i]); for (j = 0; J < m; J + +) {scanf ("%d", &w); In[i] = in[i]*10 + W; K = k*10 + 1; } for (j = 0; J < m; J + +) {scanf ("%d", &w); Out[i] = out[i]*10 + W; }} for (i = 1; I <= n; i++) {Add (I,i+50,num[i]); if (judge (0,in[i],m)) Add (0,i,inf); if (judge (k,out[i],m)) Add (I+50,101,inf); for (j = 1; J <= N; j + +) {if (i = = j) Continue; if (judge (Out[i],in[j],m)) Add (I+50,j,inf); }} while (BFS (0,101)) {while (k = DFS (0,101,inf)) Max_flow + = k; } for (i = Wuyi; I <= n+50; i++) {for (j = head[i]; J! =-1; j = p[j].next) { if (p[j].k = = INF && p[j].u! = 0 && P[J].V! = 101 && P[J].W < P[J].K) {q[sum].u = i-50; Q[SUM].V = P[J].V; Q[SUM].W = P[J].K-P[J].W; sum++; }}} if (Max_flow = = 0) printf ("0 0\n"); else {printf ("%d%d\n", Max_flow, sum); for (i = 0; i < sum; i++) printf ("%d%d%d\n", q[i].u, Q[I].V, Q[I].W); }} return 0;}
POJ3436--ACM computer Factory (Max Stream, split dinic)