int main() { freopen("a", "r", stdin); int t, n, m; cin >> t; while (t--) { cin >> n >> m; sap.init(2 * n + 2); int source = 2 * n, sink = 2 * n + 1; int tmp; for (int i = 0; i < n; i++) { cin >> tmp; sap.addCap(n + i, sink, tmp); } for (int i = 0; i < n; i++) { cin >> tmp; sap.addCap(source, i, tmp); } int a, b; for (int i = 0; i < m; i++) { cin >> a >> b; a--; b--; sap.cap[a][n + b] = inf; } cout << sap.solve(source, sink) << endl; sap.output(source, sink); if (t > 0) cout << endl; } return 0; }
int main() { freopen("a", "r", stdin); while (scanf("%d%d", &N, &M) != EOF) { int source = 0, sink = N - 1; sap.init(N); for (int i = 1; i <= M; i++) { int u, v, w; scanf("%d%d%d", &u, &v, &w); sap.addCap(u, v, w); } int tmp = sap.solve(source, sink); sap.dfs1(source); sap.dfs2(sink); sap.output(); } return 0; }