#include namespace { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" #include #pragma GCC diagnostic pop using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, k, p; cin >> n >> m >> k >> p; VI e(n), f(m), v(k); rep(i, n) cin >> e[i]; rep(i, m) cin >> f[i]; rep(i, k) cin >> v[i]; const int se = 0, sf = n, sv = sf + m, s = sv + k, t = s + 1; mf_graph g(t + 1); rep(i, k) g.add_edge(s, sv + i, v[i]); ll ans = accumulate(all(e), 0LL) + accumulate(all(f), 0LL); rep(i, n) g.add_edge(se + i, t, e[i]); rep(i, m) g.add_edge(s, sf + i, f[i]); constexpr ll INF = 100LL * 1001001001; rep(i, n) { int l; cin >> l; rep(_, l) { int ai; cin >> ai; ai--; g.add_edge(sv + ai, se + i, INF); } } rep(_, p) { int i, j; cin >> i >> j; i--, j--; g.add_edge(sf + j, se + i, INF); } auto flow = g.flow(s, t); ans -= flow; cout << ans << '\n'; vector

ms; auto c = g.min_cut(s); rep(i, k) if (!c[sv + i]) { ms.emplace_back(0, i); } rep(i, n) if (!c[se + i]) { ms.emplace_back(1, i); } rep(i, m) if (c[sf + i]) { ms.emplace_back(2, i); } cout << ms.size() << '\n'; for(auto [t, i]: ms) { cout << (t == 0 ? "Preparation" : t == 1 ? "Goal" : "Action") << ' ' << i + 1 << '\n'; } }