1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| scanf("%d%d", &m, &n); int sum = 0; for (int i = 1, x; i <= m; i++) { scanf("%d", &x); sum += x; add(n + m + 1, i, x); cin.getline(tmp, 2000); stringstream ss(tmp); while (ss >> x) { add(i, m + x, inf); } } for (int i = 1, x; i <= n; i++) { scanf("%d", &x); add(m + i, n + m + 2, x); } int ans = sum - dinic(n + m + 1, n + m + 2); for (int i = 1, flag = 0; i <= m; i++) if (dep[i]) { if (flag) putchar(' '); printf("%d", i); flag = 1; } puts(""); for (int i = m + 1, flag = 0; i <= n + m; i++) if (dep[i]) { if (flag) putchar(' '); printf("%d", i - m); flag = 1; } printf("\n%d", ans);
|