結果
問題 | No.654 Air E869120 |
ユーザー | kamojiro |
提出日時 | 2020-06-10 23:34:32 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,209 bytes |
コンパイル時間 | 104 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 19,236 KB |
最終ジャッジ日時 | 2024-06-23 19:38:16 |
合計ジャッジ時間 | 11,138 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 29 ms
18,084 KB |
testcase_01 | AC | 31 ms
11,008 KB |
testcase_02 | AC | 31 ms
11,008 KB |
testcase_03 | AC | 31 ms
11,136 KB |
testcase_04 | AC | 30 ms
10,880 KB |
testcase_05 | AC | 30 ms
11,008 KB |
testcase_06 | AC | 31 ms
10,880 KB |
testcase_07 | AC | 31 ms
11,008 KB |
testcase_08 | AC | 31 ms
11,008 KB |
testcase_09 | AC | 30 ms
11,008 KB |
testcase_10 | AC | 1,724 ms
11,520 KB |
testcase_11 | AC | 891 ms
11,392 KB |
testcase_12 | AC | 1,043 ms
11,520 KB |
testcase_13 | AC | 1,477 ms
11,392 KB |
testcase_14 | AC | 729 ms
11,648 KB |
testcase_15 | AC | 796 ms
11,392 KB |
testcase_16 | TLE | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
ソースコード
import sys input = sys.stdin.readline from collections import defaultdict INF = 10**13 class FordFulkerson: 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 dfs(self, v, t, f): if v == t: return f used = self.used used[v] = 1 for e in self.G[v]: w, cap, rev = e if cap and not used[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 f = INF N = self.N while f: self.used = [0]*N f = self.dfs(s, t, INF) flow += f return flow def main(): N, M, d = map( int, input().split()) UVPQW = [ tuple( map( int, input().split())) for _ in range(M)] E = [set() for _ in range(N)] L = 10**9 E[0].add(0) E[N-1].add(L) for u, v, p, q, _ in UVPQW: u, v = u-1, v-1 if q+d <= L: E[u].add(p) E[v].add(q+d) F = [sorted(list(E[i])) for i in range(N)] index = 0 VtoI = defaultdict( int) for i in range(N): for v in F[i]: VtoI[(i,v)] = index index += 1 I = index ff = FordFulkerson(I) for u,v,p,q,w in UVPQW: u, v = u-1, v-1 q += d if q > L: continue a = VtoI[(u,p)] b = VtoI[(v,q)] ff.add_edge(a,b,w) for i in range(N): lg = len(F[i]) for j in range(lg-1): a = VtoI[(i,F[i][j])] b = VtoI[(i, F[i][j+1])] ff.add_edge(a,b,INF) s = VtoI[(0,0)] g = VtoI[(N-1,L)] print( ff.flow(s,g)) if __name__ == '__main__': main()