結果
問題 | No.177 制作進行の宮森あおいです! |
ユーザー | tkw_tech |
提出日時 | 2016-12-01 23:39:11 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,372 bytes |
コンパイル時間 | 279 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 82,688 KB |
最終ジャッジ日時 | 2024-05-05 17:07:42 |
合計ジャッジ時間 | 3,178 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | AC | 65 ms
67,432 KB |
testcase_14 | RE | - |
testcase_15 | RE | - |
ソースコード
# 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: 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")