結果
問題 | No.2713 Just Solitaire |
ユーザー | sepa38 |
提出日時 | 2024-03-31 12:34:15 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 105 ms / 2,000 ms |
コード長 | 1,999 bytes |
コンパイル時間 | 188 ms |
コンパイル使用メモリ | 82,144 KB |
実行使用メモリ | 78,080 KB |
最終ジャッジ日時 | 2024-09-30 17:54:54 |
合計ジャッジ時間 | 3,998 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
54,144 KB |
testcase_01 | AC | 44 ms
53,888 KB |
testcase_02 | AC | 45 ms
54,784 KB |
testcase_03 | AC | 87 ms
76,416 KB |
testcase_04 | AC | 76 ms
71,936 KB |
testcase_05 | AC | 56 ms
62,464 KB |
testcase_06 | AC | 92 ms
77,568 KB |
testcase_07 | AC | 57 ms
62,336 KB |
testcase_08 | AC | 47 ms
54,656 KB |
testcase_09 | AC | 51 ms
60,160 KB |
testcase_10 | AC | 57 ms
63,616 KB |
testcase_11 | AC | 66 ms
67,072 KB |
testcase_12 | AC | 61 ms
63,744 KB |
testcase_13 | AC | 82 ms
74,624 KB |
testcase_14 | AC | 69 ms
69,760 KB |
testcase_15 | AC | 45 ms
54,272 KB |
testcase_16 | AC | 53 ms
61,568 KB |
testcase_17 | AC | 71 ms
68,352 KB |
testcase_18 | AC | 48 ms
55,040 KB |
testcase_19 | AC | 95 ms
77,568 KB |
testcase_20 | AC | 45 ms
54,528 KB |
testcase_21 | AC | 47 ms
54,400 KB |
testcase_22 | AC | 57 ms
62,080 KB |
testcase_23 | AC | 75 ms
70,656 KB |
testcase_24 | AC | 81 ms
72,704 KB |
testcase_25 | AC | 105 ms
78,080 KB |
testcase_26 | AC | 96 ms
77,952 KB |
testcase_27 | AC | 101 ms
77,824 KB |
testcase_28 | AC | 102 ms
77,824 KB |
testcase_29 | AC | 100 ms
77,824 KB |
testcase_30 | AC | 100 ms
78,080 KB |
testcase_31 | AC | 86 ms
74,952 KB |
testcase_32 | AC | 105 ms
77,824 KB |
testcase_33 | AC | 99 ms
77,696 KB |
ソースコード
from collections import deque class Dinic: def __init__(self, N): self.N = N self.G = [[] for i in range(N)] def add_edge(self, fr, to, cap): forward = [to, cap, None] forward[2] = backward = [fr, 0, forward] self.G[fr].append(forward) self.G[to].append(backward) def add_multi_edge(self, v1, v2, cap1, cap2): edge1 = [v2, cap1, None] edge1[2] = edge2 = [v1, cap2, edge1] self.G[v1].append(edge1) self.G[v2].append(edge2) def bfs(self, s, t): self.level = level = [None]*self.N deq = deque([s]) level[s] = 0 G = self.G while deq: v = deq.popleft() lv = level[v] + 1 for w, cap, _ in G[v]: if cap and level[w] is None: level[w] = lv deq.append(w) return level[t] is not None def dfs(self, v, t, f): if v == t: return f level = self.level for e in self.it[v]: w, cap, rev = e if cap and level[v] < level[w]: d = self.dfs(w, t, min(f, cap)) if d: e[1] -= d rev[1] += d return d return 0 def flow(self, s, t): flow = 0 INF = 10**9 + 7 G = self.G while self.bfs(s, t): *self.it, = map(iter, self.G) f = INF while f: f = self.dfs(s, t, INF) flow += f return flow n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = [] for _ in range(m): c.append(list(map(lambda x: int(x)-1, input().split()))[1:]) g = Dinic(n+m+2) inf = 1 << 30 for i in range(n): g.add_edge(0, i+1, a[i]) for i in range(m): g.add_edge(n+i+1, n+m+1, b[i]) for v in range(m): for u in c[v]: g.add_edge(u+1, n+v+1, inf) print(sum(b) - g.flow(0, n+m+1))