結果
問題 | No.177 制作進行の宮森あおいです! |
ユーザー | tkw_tech |
提出日時 | 2016-12-01 23:39:43 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 96 ms / 2,000 ms |
コード長 | 2,412 bytes |
コンパイル時間 | 143 ms |
コンパイル使用メモリ | 82,240 KB |
実行使用メモリ | 79,832 KB |
最終ジャッジ日時 | 2024-11-27 16:42:13 |
合計ジャッジ時間 | 1,899 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 66 ms
69,028 KB |
testcase_01 | AC | 59 ms
68,132 KB |
testcase_02 | AC | 57 ms
69,032 KB |
testcase_03 | AC | 59 ms
69,152 KB |
testcase_04 | AC | 59 ms
68,688 KB |
testcase_05 | AC | 62 ms
71,012 KB |
testcase_06 | AC | 70 ms
73,260 KB |
testcase_07 | AC | 59 ms
69,148 KB |
testcase_08 | AC | 65 ms
72,500 KB |
testcase_09 | AC | 93 ms
79,832 KB |
testcase_10 | AC | 96 ms
79,692 KB |
testcase_11 | AC | 86 ms
78,972 KB |
testcase_12 | AC | 90 ms
79,532 KB |
testcase_13 | AC | 56 ms
68,328 KB |
testcase_14 | AC | 57 ms
67,912 KB |
testcase_15 | AC | 58 ms
68,392 KB |
ソースコード
# coding: utf-8 import queue class Dinic: """Implementation of Dinic's Alogorithm""" def __init__(self, v, inf = 1000000007): self.V = v self.inf = inf self.G = [[] for _ in range(v)] self.level = [0 for _ in range(v)] self.iter = [0 for _ in range(v)] def add_edge(self, from_, to, cap): # to: 行き先, cap: 容量, rev: 反対側の辺 self.G[from_].append({'to':to, 'cap':cap, 'rev':len(self.G[to])}) self.G[to].append({'to':from_, 'cap':0, 'rev':len(self.G[from_])-1}) # sからの最短距離をbfsで計算 def bfs(self, s): self.level = [-1 for _ in range(self.V)] self.level[s] = 0; que = queue.Queue() que.put(s) while not que.empty(): v = que.get() for i in range(len(self.G[v])): e = self.G[v][i] if e['cap'] > 0 and self.level[e['to']] < 0: self.level[e['to']] = self.level[v] + 1 que.put(e['to']) # 増加バスをdfsで探す def dfs(self, v, t, f): if v == t: return f for i in range(self.iter[v], len(self.G[v])): self.iter[v] = i e = self.G[v][i] if e['cap'] > 0 and self.level[v] < self.level[e['to']]: d = self.dfs(e['to'], t, min(f, e['cap'])) if d > 0: e['cap'] -= d self.G[e['to']][e['rev']]['cap'] += d return d return 0 def max_flow(self, s, t): flow = 0 while True: self.bfs(s) # bfsで到達不可 if self.level[t] < 0 : return flow self.iter = [0 for _ in range(self.V)] f = self.dfs(s, t, self.inf) while f > 0: flow += f f = self.dfs(s,t, self.inf) W = int(input()) N = int(input()) J = [int(x) for x in input().split()] M = int(input()) C = [int(x) for x in input().split()] mf = Dinic(N+M+2) source, sink = N+M, N+M+1 INF = 10**9 for i, j in enumerate(J): mf.add_edge(source, i, j) for i, c in enumerate(C): mf.add_edge(N+i, sink, c) _, *X = [int(x)-1 for x in input().split()] for j in range(N): if j not in X: mf.add_edge(j, i+N, INF) maxflow = mf.max_flow(source, sink) print("SHIROBAKO" if maxflow >= W else "BANSAKUTSUKITA")