結果
問題 | No.654 Air E869120 |
ユーザー | tonnnura172 |
提出日時 | 2020-05-14 01:50:51 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,419 bytes |
コンパイル時間 | 429 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 90,752 KB |
最終ジャッジ日時 | 2024-09-14 15:48:34 |
合計ジャッジ時間 | 7,607 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | RE | - |
testcase_38 | RE | - |
testcase_39 | RE | - |
ソースコード
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 class Dinic: def __init__(self, v, inf =10**10): self.v = v self.inf = inf self.G = [[] for _ in range(v)] self.level = [-1]*v # 深さ self.ite = [0]*v # DFSでの探索が済んでいるか def add_edge(self, fr, to, cap): self.G[fr].append([to, cap, len(self.G[to])]) self.G[to].append([fr, 0, len(self.G[fr])-1]) def bfs(self, s): # BFSで深さ決定,sがstart self.level = [-1]*self.v # 必要 self.level[s] = 0 Q = deque() Q.append(s) while Q: v = Q.popleft() for i in range(len(self.G[v])): e = self.G[v][i] if e[1]>0 and self.level[e[0]]<0: ###capacity>0かつtoの深さ未定 self.level[e[0]] = self.level[v]+1 Q.append(e[0]) def dfs(self, v, t, f): # DFSで増加パス探索,v開始、t終点、総フローf if v==t: return f for i in range(self.ite[v],len(self.G[v])): self.ite[v] = i e = self.G[v][i] if e[1]>0 and self.level[v]<self.level[e[0]]: d = self.dfs(e[0], t, min(f, e[1])) if d>0: e[1] -= d # cap減少 self.G[e[0]][e[2]][1] += d # 逆辺のcap増加 return d return 0 def max_flow(self, s, t): flow = 0 while True: self.bfs(s) if self.level[t]<0: return flow self.ite = [0]*self.v # DFSでの探索が済んでいるか否か f = self.dfs(s,t,self.inf) while f>0: flow+= f f = self.dfs(s,t,self.inf) def compress(A): zipped, unzipped = {}, {} for i, a in enumerate(sorted(A)): zipped[a] = i unzipped[i] = a return zipped, unzipped N, M, d = MAP() S = set() edges = [] for _ in range(M): u, v, p, q, w = MAP() q += d u -= 1 v -= 1 S.add(p) S.add(q) edges.append((u, v, p, q, w)) zipped, _ = compress(S) for i, (u, v, p, q, w) in enumerate(edges): p = zipped[p] q = zipped[q] edges[i] = (u, v, p, q, w) L = len(zipped) # フライトの時間の数 D = Dinic(N*L) ## N*Lのgridができる A = [[] for _ in range(N)] A[0].append(0) for u, v, p, q, w in edges: D.add_edge(u*L+p, v*L+q, w) A[u].append(p) A[v].append(q) for i in range(N): A[i].sort() for j in range(len(A[i])-1): p, q = A[i][j], A[i][j+1] D.add_edge(i*L+p, i*L+q, INF) ans = D.max_flow(0, (N-1)*L+L-1) print(ans)