結果

問題 No.654 Air E869120
ユーザー PNJPNJ
提出日時 2023-11-09 02:13:48
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 2,124 bytes
コンパイル時間 335 ms
コンパイル使用メモリ 12,160 KB
実行使用メモリ 38,144 KB
最終ジャッジ日時 2023-11-09 02:14:15
合計ジャッジ時間 24,368 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,240 KB
testcase_01 AC 30 ms
10,240 KB
testcase_02 WA -
testcase_03 AC 31 ms
10,240 KB
testcase_04 WA -
testcase_05 AC 31 ms
10,240 KB
testcase_06 AC 30 ms
10,240 KB
testcase_07 WA -
testcase_08 AC 30 ms
10,240 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 660 ms
13,568 KB
testcase_28 WA -
testcase_29 AC 721 ms
13,440 KB
testcase_30 AC 645 ms
11,008 KB
testcase_31 AC 674 ms
11,008 KB
testcase_32 AC 649 ms
11,008 KB
testcase_33 AC 645 ms
11,008 KB
testcase_34 AC 617 ms
11,008 KB
testcase_35 AC 30 ms
10,240 KB
testcase_36 AC 29 ms
10,240 KB
testcase_37 AC 29 ms
10,240 KB
testcase_38 AC 29 ms
10,240 KB
testcase_39 AC 34 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(i+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