Test instructions a little hard to read.
Network flow-ek Algorithm-ACM computer Factory-composition Focus//time:0ms Memory:208k#include <iostream> #include <cstring> #include <cstdio > #include <algorithm> #include <queue>using namespace std; #define MAXN 55#define INF 0x3f3f3f3fint p,n; int s,t;int comp[maxn][22];int bd[maxn][maxn];int res[maxn][maxn];int pre[maxn];bool bfs () {memset (pre,-1,sizeof (PRE) ); Queue<int> Q; Q.push (s); Pre[s] = 0; while (!q.empty ()) {int cur = q.front (); Q.pop (); for (int i = 1; I <= t; i++) {if (pre[i] = = 1 && res[cur][i]) {Pre [I] = cur; if (i = = t) return true; Q.push (i); }}} return false;} int EK (int &total) {int maxflow = 0; while (BFS ()) {int mind = INF; for (int i = t; I! = s; i = pre[i]) mind = min (mind, res[pre[i]][i]); for (int i = t; I! = s; i = Pre[i]) {if (I! = t && pre[i]! = s && res[pre[I]][i] = = Bd[pre[i]][i]) total++; Res[pre[i]][i]-= mind; Res[i][pre[i] + + + mind; if (i! = t && pre[i]! = S && res[i][pre[i]] = = Bd[i][pre[i]]) total--; } Maxflow + = mind; } return maxflow;} int main () {//freopen ("In.txt", "R", stdin); scanf ("%d%d", &p,&n); s = 0; t = n + 1; Input + composition for (int i = 1; I <= n; i++) {bool in = true, out = true; for (int j = 0; J <= P*2; j + +) {scanf ("%d", &comp[i][j]); if (J >= 1 && J <= p && comp[i][j] = = 1) in = false; if (J > P &&!comp[i][j]) out = false; Not finished} if (in) bd[s][i] = comp[i][0]; if (out) bd[i][t] = comp[i][0]; } for (int i = 1, i <= N; i++) for (int j = 1; J <= N; j + +) {bool con = true; if (i = = j) Continue; for (int k = 1; k <= p; k++) {if (comp[j][k] = 2 && comp[i][k + p]! = Comp[j][k])//Determine whether this line can be transmitted {con = false; Break }} if (Con) bd[i][j] = comp[i][0]; Connection} memcpy (res, BD, sizeof (BD)); int total = 0; int maxflow = EK (total); printf ("%d%d\n", Maxflow, total); for (int i = 1, i <= N; i++) for (int j = 1; J <= N; j + +) {if (Bd[i][j] && Bd[i][j] & Gt RES[I][J]) printf ("%d%d%d\n", I, J, Bd[i][j]-res[i][j]); } return 0;}
ACM/ICPC ACM Computer Factory-ek Algorithm (POJ3436)