結果

問題 No.654 Air E869120
ユーザー PNJPNJ
提出日時 2023-11-09 02:15:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 2,122 bytes
コンパイル時間 387 ms
コンパイル使用メモリ 12,160 KB
実行使用メモリ 71,808 KB
最終ジャッジ日時 2023-11-09 02:16:35
合計ジャッジ時間 44,030 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
10,240 KB
testcase_01 AC 34 ms
10,240 KB
testcase_02 AC 32 ms
10,240 KB
testcase_03 AC 34 ms
10,240 KB
testcase_04 AC 37 ms
10,240 KB
testcase_05 AC 35 ms
10,240 KB
testcase_06 AC 35 ms
10,240 KB
testcase_07 AC 36 ms
10,240 KB
testcase_08 AC 33 ms
10,240 KB
testcase_09 AC 33 ms
10,240 KB
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 AC 1,588 ms
28,288 KB
testcase_17 AC 1,571 ms
28,288 KB
testcase_18 AC 1,522 ms
28,288 KB
testcase_19 AC 1,593 ms
28,160 KB
testcase_20 AC 1,444 ms
19,328 KB
testcase_21 AC 1,462 ms
19,456 KB
testcase_22 AC 1,385 ms
19,456 KB
testcase_23 AC 1,392 ms
19,456 KB
testcase_24 AC 1,443 ms
19,200 KB
testcase_25 AC 1,349 ms
18,944 KB
testcase_26 AC 1,370 ms
19,200 KB
testcase_27 AC 1,430 ms
16,256 KB
testcase_28 AC 1,382 ms
16,256 KB
testcase_29 AC 1,301 ms
16,000 KB
testcase_30 AC 1,351 ms
11,392 KB
testcase_31 AC 1,358 ms
11,520 KB
testcase_32 AC 1,307 ms
11,520 KB
testcase_33 AC 1,326 ms
11,392 KB
testcase_34 AC 1,314 ms
11,392 KB
testcase_35 AC 31 ms
10,240 KB
testcase_36 AC 31 ms
10,240 KB
testcase_37 AC 32 ms
10,240 KB
testcase_38 AC 31 ms
10,240 KB
testcase_39 AC 35 ms
10,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline

class Dinic:
  def __init__(self,V):
    self.V = V
    self.E = [[] for i in range(V)]
    self.P = [0 for i in range(V)]
  
  def add_edge(self,u,v,cap):
    self.E[u].append((v,cap,self.P[v]))
    self.E[v].append((u,0,self.P[u]))
    self.P[u] += 1
    self.P[v] += 1

  def flow(self,s,t):
    G = self.E
    P = self.P
    def bfs(s):  #始点から各頂点への最短距離をBFSで求める。
      dist = [-1 for i in range(self.V)]
      dist[s] = 0
      Q = deque()
      Q.append(s)
      while len(Q) > 0:
        u = Q.popleft()
        for v,cap,rev in G[u]:
          if cap > 0 and dist[v] < 0:
            dist[v] = dist[u] + 1
            Q.append(v)
      return dist

    def dfs(u,t,f,removed,dist):
      if u == t:
        return f
      while removed[u] < P[u]:
        v,cap,rev = G[u][removed[u]]
        if cap > 0 and dist[u] < dist[v]:
          ff = dfs(v,t,min(f,cap),removed,dist)
          if ff > 0:
            G[u][removed[u]] = (v,cap-ff,rev)
            u,Cap,Rev = G[v][rev]
            G[v][rev] = (u,Cap+ff,Rev)
            return ff
        removed[u] += 1
      return 0

    f = 0
    while True:
      dist = bfs(s)
      if dist[t] < 0:
        return f
      removed = [0 for i in range(self.V)]
      while True:
        ff = dfs(s,t,10000000000,removed,dist)
        if ff == 0:
          break
        f += ff

N,M,d = map(int,input().split())
G = Dinic(2*M+2)
X = [0]
for i in range(M):
  u,v,p,q,w = map(int,input().split())
  G.add_edge(2*i+1,2*i+2,w)
  X.append((u,p,0))
  X.append((v,q,1))

inf = 10**18
for i in range(1,2*M+1):
  v,t,f = X[i]
  if f == 0:
    if v == 1:
      G.add_edge(0,i,inf)
  else:
    if v == N:
      G.add_edge(i,2*M+1,inf)
  for j in range(1,2*M+1):
    u,tt,ff = X[j]
    if f == 0 and ff == 0:
      if u == v:
        if t <= tt:
          G.add_edge(i,j,inf)
        if t >= tt:
          G.add_edge(j,i,inf)
    if f == 1 and ff == 0:
      if t + d <= tt and u == v:
        G.add_edge(i,j,inf)

ans = G.flow(0,2*M+1)
print(ans)
0