Language: C

#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#define N 200015
#define M 600300
using namespace std;

class FlowNetwork {
	struct ARC {
		int u, cap, next;
		inline void init(int a, int b, int c) {
			u = a, cap = b, next = c;
		}
	} arc[M];
	int head[N], n, m, source, sink;
	int c[N << 1], d[N], pf[N], cur[N];
	bool in[N];
	queue<int> lab[N * 2], Q;

	void init(int _n, int _source, int _sink) {
		n = _n, m = 0, source = _source, sink = _sink;
		fill(head, head + n, -1);
	}

	void add_arc(int s, int t, int cap) {
		arc[m].init(t, cap, head[s]);
		head[s] = m++;
		arc[m].init(s, 0, head[t]);
		head[t] = m++;
	}

	void BFS() {
		fill(c, c + n * 2, 0);
		fill(d, d + n, n + 1);
		d[source] = n, d[sink] = 0;
		Q.push(sink), c[n + 1] = n - 1;
		for (int u; !Q.empty();) {
			u = Q.front(), Q.pop();
			--c[n + 1], ++c[d[u]];
			for (int e = head[u]; e != -1; e = arc[e].next) {
				int v = arc[e].u;
				if (!(d[v] == n + 1 && arc[e ^ 1].cap > 0))
					continue;
				d[v] = d[u] + 1, Q.push(v);
			}
		}
	}

	int HLPP() {
		fill(in, in + n, false);
		for (int i = 0; i < n + n; i++)
			if (!lab[i].empty())
				lab[i].pop();
		int todo = -1;
		BFS();
		in[source] = in[sink] = true;
		fill(pf, pf + n, 0);
		for (int e = head[source], v; e != -1; e = arc[e].next) {
			pf[v = arc[e].u] += arc[e].cap;
			arc[e ^ 1].cap += arc[e].cap, arc[e].cap = 0;
			if (in[v])
				continue;
			in[v] = true, lab[d[v]].push(v);
			todo = max(todo, d[v]);
		}
		for (int i = 0; i < n; i++)
			cur[i] = head[i];
		for (int tmp; todo >= 0;) {
			while (todo >= 0 && lab[todo].empty())
				todo--;
			if (todo < 0)
				break;
			int u = lab[todo].front();
			in[u] = false, lab[todo].pop();
			for (int v, f; cur[u] != -1; cur[u] = arc[cur[u]].next) {
				v = arc[cur[u]].u;
				if (d[u] != d[v] + 1 || arc[cur[u]].cap == 0)
					continue;
				f = min(pf[u], arc[cur[u]].cap);
				pf[u] -= f, pf[v] += f;
				arc[cur[u]].cap -= f, arc[cur[u] ^ 1].cap += f;
				if (!in[v])
					in[v] = true, lab[d[v]].push(v);
				if (pf[u] == 0)
					break;
			}
			if (pf[u] == 0)
				continue;
			tmp = d[u], --c[tmp], d[u] = n * 2;
			for (int e = head[u]; e != -1; e = arc[e].next) {
				int v = arc[e].u;
				if (d[u] <= d[v] + 1 || arc[e].cap == 0)
					continue;
				d[u] = d[v] + 1, cur[u] = e;
			}
			++c[d[u]], todo = d[u];
			in[u] = true, lab[d[u]].push(u);
			if (c[tmp])
				continue;
			for (int i = 0; i < n; i++)
				if (d[i] > tmp && d[i] < n + 1)
					--c[d[i]], ++c[n + 1], d[i] = n + 1;
		}
		return pf[sink];
	}
};

FlowNetwork fn;
int T, n, m, L, s, t;
int r[410];
int l[410];
int main() {
	//freopen("data.in","r",stdin);
	//freopen("data.out","w",stdout);
	int n, m, k;
	while (scanf("%d%d%d", &n, &m, &k) != EOF) {
		int sum1, sum2;
		sum1 = sum2 = 0;
		for (int i = 0; i < n; ++i) {
			scanf("%d", &r[i]);
			sum1 += r[i];
		}
		for (int j = 0; j < m; ++j) {
			scanf("%d", &c[i]);
			sum2 += c[j];
		}
		if (sum1 != sum2) {
			puts("Impossible");
			continue;
		}
		int s, t;
		s = n * m * 2 + n + m;
		t = s + 1;
		fn.init(t + 1, s, t);
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				int id = i * n + j;
				fn.add_arc(id, id + n * m, k);
			}
		}
		for (int i = 0; i < n; ++i) {

			int now = n * m * 2 + i;
			fn.add_arc(s, now, r[i]);
			for (int j = 0; j < m; ++j) {
				fn.add_arc(now, i * n + j, k);
			}
		}
		for (int j = 0; j < m; ++j) {
			int now = n * m * 2 + n + j;
			fn.add_arc(now, t, c[j]);
			for (int i = 0; i < n; ++i) {
				fn.add_arc(i * n + j + n * m, now, k);
			}
		}
		int ans = fn.HLPP();
		if (ans != sum1)
			puts("Impossible");
		else {
			puts("Unique");
			for (int i = 0; i < n; ++i) {
				for (int j = 0; j < m - 1; ++j) {
					int now = i * n + j;
					printf("%d ", fn.arc[now << 1 | 1]);

				}
				int now = i * n + m-1;
				printf("%d\n", fn.arc[now << 1 | 1]);
			}
		}

	}
	return 0;
}

Compiler output:
main.c:1:10: fatal error: iostream: No such file or directory
    1 | #include <iostream>
      |          ^~~~~~~~~~
compilation terminated.