n = read(), m = read(); S = n * m + 1, T = n * m + 2;
for (int i = 1; i <= n; i ++) { for (int j = 1; j <= m; j ++) { a[i][j] = read(), c[i][j] = (i - 1) * m + j; } }
for (int i = 1; i <= n; i ++) { for (int j = 1; j <= m; j ++) { res += a[i][j]; if ((i + j) & 1) { addE(S, c[i][j], a[i][j]); if (i > 1) addE(c[i][j], c[i - 1][j], INF); if (j > 1) addE(c[i][j], c[i][j - 1], INF); if (i < n) addE(c[i][j], c[i + 1][j], INF); if (j < m) addE(c[i][j], c[i][j + 1], INF); } elseaddE(c[i][j], T, a[i][j]); } } while (bfs()) res -= dfs(S, INF);
n = read(), m = read(); S = n * n + 1, T = n * n + 2;
for (int i = 1; i <= m; i ++) { int x = read(), y = read(); a[x][y] = 1; } for (int i = 1; i <= n; i ++) { for (int j = 1; j <= n; j ++) { if (a[i][j] == 1) continue; if ((i + j) & 1) { addE(S, F(i, j), 1); for (int k = 0; k < 8; k ++) { int x = i + dx[k], y = j + dy[k]; if (x < 1 || x > n || y < 1 || y > n) continue; if (a[x][y] == 1) continue; addE(F(i, j), F(x, y), INF); } } elseaddE(F(i, j), T, 1); } }
res = n * n - m; while (bfs()) res -= dfs(S, INF);
n = read(), m = read(), k = read(); S = ++cnt, T = ++cnt;
for (int i = 1; i <= n + 2; i ++) fa[i] = i; for (int i = 1; i <= m; i ++) { h[i] = read(), r[i] = read(); for (int j = 1; j <= r[i]; j ++) { s[i][j] = read(); if (s[i][j] == 0) s[i][j] = n + 1; if (s[i][j] == -1) s[i][j] = n + 2; if (j > 1) fa[getF(s[i][j])] = getF(s[i][j - 1]); } }
if (getF(n + 1) != getF(n + 2)) returnputs("0"), 0;
int sum = 0; for (int i = 1; ; i ++) { for (int j = 1; j <= n + 2; j ++) { c[i][j] = ++ cnt; if (i > 1) addE(c[i - 1][j], c[i][j], INF); } addE(S, c[i][n + 1], INF); addE(c[i][n + 2], T, INF); if (i == 1) continue; for (int j = 1; j <= m; j ++) { int t1 = (i - 2) % r[j] + 1; int t2 = (i - 1) % r[j] + 1; addE(c[i - 1][s[j][t1]], c[i][s[j][t2]], h[j]); } while (bfs()) sum += dfs(S, INF); if (sum >= k) returnprintf("%d\n", i - 1), 0; }
m = read(), n = read(); S = n + m + 1, T = n + m + 2;
for (int i = 1; i <= n; i ++) addE(S, i, 1); for (int i = 1, x; i <= m; i ++) { x = read(), sum += x; addE(i + n, T, x); } for (int i = 1; i <= n; i ++) { int x = read(); for (int j = 1; j <= x; j ++) { addE(i, read() + n, 1); } }
int Mx = 0; while (bfs()) Mx += dfs(S, INF); if (Mx < sum) returnputs("No Solution!"), 0;
for (int i = 1; i <= tot; i ++) { if (e[i].y == S || e[i ^ 1].y == S) continue; if (e[i].y == T || e[i ^ 1].y == T) continue; if (e[i].y <= n) continue; if (e[i].v == 0) vec[e[i].y - n].pb(e[i ^ 1].y); } for (int i = 1; i <= m; i ++, puts("")) { printf("%d: ", i); for (auto j : vec[i]) printf("%d ", j); }