結果
問題 | No.2713 Just Solitaire |
ユーザー | tnakao0123 |
提出日時 | 2024-04-30 11:29:36 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 8 ms / 2,000 ms |
コード長 | 2,960 bytes |
コンパイル時間 | 901 ms |
コンパイル使用メモリ | 72,192 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-04-30 11:29:38 |
合計ジャッジ時間 | 2,119 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 4 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 4 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 3 ms
6,944 KB |
testcase_12 | AC | 2 ms
6,944 KB |
testcase_13 | AC | 3 ms
6,944 KB |
testcase_14 | AC | 2 ms
6,944 KB |
testcase_15 | AC | 2 ms
6,940 KB |
testcase_16 | AC | 2 ms
6,940 KB |
testcase_17 | AC | 3 ms
6,944 KB |
testcase_18 | AC | 2 ms
6,940 KB |
testcase_19 | AC | 4 ms
6,940 KB |
testcase_20 | AC | 2 ms
6,944 KB |
testcase_21 | AC | 2 ms
6,940 KB |
testcase_22 | AC | 1 ms
6,944 KB |
testcase_23 | AC | 3 ms
6,940 KB |
testcase_24 | AC | 8 ms
6,940 KB |
testcase_25 | AC | 8 ms
6,944 KB |
testcase_26 | AC | 7 ms
6,944 KB |
testcase_27 | AC | 8 ms
6,944 KB |
testcase_28 | AC | 8 ms
6,948 KB |
testcase_29 | AC | 8 ms
6,940 KB |
testcase_30 | AC | 7 ms
6,940 KB |
testcase_31 | AC | 7 ms
6,944 KB |
testcase_32 | AC | 8 ms
6,940 KB |
testcase_33 | AC | 6 ms
6,940 KB |
ソースコード
/* -*- coding: utf-8 -*- * * 2713.cc: No.2713 Just Solitaire - yukicoder */ #include<cstdio> #include<vector> #include<queue> #include<algorithm> #include<utility> using namespace std; /* constant */ const int MAX_N = 100; const int MAX_M = 100; const long long LINF = 1LL << 60; /* typedef */ typedef long long ll; template <typename T> struct MaxFlow { typedef pair<int,int> pii; typedef vector<pii> vpii; typedef vector<vpii> vvpii; int n, m; vvpii nbrs; T inf; vpii prvs; vector<T> minfs, caps, flows; MaxFlow(int _n, T _inf): n(_n), m(0), inf(_inf) { nbrs.assign(n, vpii()); minfs.assign(n, 0); prvs.assign(n, pii(-1, -1)); caps.clear(), flows.clear(); } int addedges(int u, int v, T c) { // edge[m]: u -> v, cap=c nbrs[u].push_back(pii(v, m)); caps.push_back(c); flows.push_back(0); // edge[m + 1]: v -> u, cap=0 nbrs[v].push_back(pii(u, m + 1)); caps.push_back(0); flows.push_back(0); m += 2; return m; } T flow(int st, int gl) { fill(flows.begin(), flows.end(), 0); T max_flow = 0; for (;;) { //printf("max_flow = %d, limit = %d\n", max_flow, limit); fill(prvs.begin(), prvs.end(), pii(-1, -1)); prvs[st] = pii(st, -1); minfs[st] = inf; queue<int> q; q.push(st); while (! q.empty()) { int ui = q.front(); q.pop(); if (ui == gl) break; vpii& nbru = nbrs[ui]; for (vpii::iterator vit = nbru.begin(); vit != nbru.end(); vit++) { int vi = vit->first, ei = vit->second; T vc = caps[ei] - flows[ei]; if (prvs[vi].first < 0 && vc > 0) { prvs[vi] = pii(ui, ei); minfs[vi] = (minfs[ui] < vc) ? minfs[ui] : vc; q.push(vi); } } } if (prvs[gl].first < 0) break; T min_flow = minfs[gl]; for (int j = gl; j != st;) { int i = prvs[j].first, ei = prvs[j].second; flows[ei] += min_flow; flows[ei ^ 1] -= min_flow; j = i; } max_flow += min_flow; } return max_flow; } }; /* int main() { const int INF = 1 << 30; MaxFlow<int> mf(3, INF); mf.addedges(0, 1, 1); mf.addedges(1, 2, 3); mf.addedges(0, 2, 1); int f = mf.flow(0, 2); printf("f=%d\n", f); return 0; } */ /* global variables */ int as[MAX_N], bs[MAX_M]; /* subroutines */ /* main */ int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%d", as + i); for (int i = 0; i < m; i++) scanf("%d", bs + i); int st = n + m, gl = st + 1, gn = gl + 1; MaxFlow<ll> mf(gn, LINF); for (int i = 0; i < n; i++) mf.addedges(st, i, as[i]); for (int i = 0; i < m; i++) mf.addedges(n + i, gl, bs[i]); for (int i = 0; i < m; i++) { int ki; scanf("%d", &ki); for (int j = 0; j < ki; j++) { int cj; scanf("%d", &cj); cj--; mf.addedges(cj, n + i, LINF); } } ll xf = mf.flow(st, gl); ll bsum = 0; for (int i = 0; i < m; i++) bsum += bs[i]; printf("%lld\n", bsum - xf); return 0; }