結果
問題 | No.177 制作進行の宮森あおいです! |
ユーザー | n_knuu |
提出日時 | 2016-10-15 20:16:17 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 38 ms / 2,000 ms |
コード長 | 2,561 bytes |
コンパイル時間 | 89 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 11,264 KB |
最終ジャッジ日時 | 2024-11-22 11:52:17 |
合計ジャッジ時間 | 1,478 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
10,880 KB |
testcase_01 | AC | 34 ms
10,880 KB |
testcase_02 | AC | 35 ms
10,880 KB |
testcase_03 | AC | 31 ms
10,880 KB |
testcase_04 | AC | 33 ms
10,880 KB |
testcase_05 | AC | 34 ms
11,008 KB |
testcase_06 | AC | 34 ms
11,136 KB |
testcase_07 | AC | 32 ms
10,880 KB |
testcase_08 | AC | 33 ms
10,880 KB |
testcase_09 | AC | 38 ms
11,136 KB |
testcase_10 | AC | 37 ms
11,264 KB |
testcase_11 | AC | 36 ms
11,136 KB |
testcase_12 | AC | 36 ms
11,136 KB |
testcase_13 | AC | 31 ms
10,880 KB |
testcase_14 | AC | 31 ms
11,008 KB |
testcase_15 | AC | 31 ms
10,880 KB |
ソースコード
import collections class MaxFlow: """Dinic Algorithm: find max-flow complexity: O(EV^2) used in GRL6A(AOJ) """ class Edge: def __init__(self, to, cap, rev): self.to, self.cap, self.rev = to, cap, rev def __init__(self, V): """ V: the number of vertexes E: adjacency list source: start point sink: goal point """ self.V = V self.E = [[] for _ in range(V)] def add_edge(self, fr, to, cap): self.E[fr].append(self.Edge(to, cap, len(self.E[to]))) self.E[to].append(self.Edge(fr, 0, len(self.E[fr])-1)) def dinic(self, source, sink, INF=10**9): """find max-flow""" maxflow = 0 while True: self.bfs(source) if self.level[sink] < 0: return maxflow self.itr = [0] * self.V while True: flow = self.dfs(source, sink, INF) if flow > 0: maxflow += flow else: break def dfs(self, vertex, sink, flow): """find augmenting path""" if vertex == sink: return flow for i in range(self.itr[vertex], len(self.E[vertex])): self.itr[vertex] = i e = self.E[vertex][i] if e.cap > 0 and self.level[vertex] < self.level[e.to]: d = self.dfs(e.to, sink, min(flow, e.cap)) if d > 0: e.cap -= d self.E[e.to][e.rev].cap += d return d return 0 def bfs(self, start): """find shortest path from start""" que = collections.deque() self.level = [-1] * self.V que.append(start) self.level[start] = 0 while que: fr = que.popleft() for e in self.E[fr]: if e.cap > 0 and self.level[e.to] < 0: self.level[e.to] = self.level[fr] + 1 que.append(e.to) 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 = MaxFlow(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.dinic(source, sink) print("SHIROBAKO" if maxflow >= W else "BANSAKUTSUKITA")