結果

問題 No.1744 Selfish Spies 1 (à la Princess' Perfectionism)
ユーザー kozykozy
提出日時 2021-11-14 21:52:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 2,212 bytes
コンパイル時間 103 ms
コンパイル使用メモリ 11,296 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2023-08-20 06:38:28
合計ジャッジ時間 17,864 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,980 KB
testcase_01 AC 19 ms
8,964 KB
testcase_02 AC 20 ms
8,796 KB
testcase_03 AC 20 ms
8,996 KB
testcase_04 AC 19 ms
9,004 KB
testcase_05 AC 19 ms
8,864 KB
testcase_06 AC 20 ms
9,008 KB
testcase_07 AC 20 ms
8,948 KB
testcase_08 AC 20 ms
8,944 KB
testcase_09 AC 35 ms
8,904 KB
testcase_10 AC 39 ms
8,988 KB
testcase_11 AC 59 ms
8,928 KB
testcase_12 AC 344 ms
8,968 KB
testcase_13 AC 119 ms
9,116 KB
testcase_14 AC 1,183 ms
9,340 KB
testcase_15 AC 573 ms
9,596 KB
testcase_16 AC 2,308 ms
9,720 KB
testcase_17 TLE -
testcase_18 TLE -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000000)
from collections import deque
class Dinic():
  def __init__(self,V):
    self.v=V#頂点数
    self.G=[list() for i in range(self.v)]
    self.inf=float("inf")
    self.level=[-1]*self.v
    self.see=[0]*self.v
  def add(self,fro,to,cost):
    self.G[fro].append([cost,to,len(self.G[to])])#cost,to,rev
    self.G[to].append([0,fro,len(self.G[fro])-1])
  #sから各辺の距離をbfsで求める
  def bfs(self,s):
    self.level=[-1]*self.v
    self.level[s]=0
    d=deque()
    d.append(s)
    while d:
      site=d.popleft()
      for e in self.G[site]:
        if self.level[e[1]]==-1 and e[0]>0:
          self.level[e[1]]=self.level[site]+1
          d.append(e[1])
  #フローをsからtへ、f流すとどうなるか
  #増加
  def dfs(self,s,t,f):
    if s==t:
      return f
    for i in range(self.see[s],len(self.G[s])):
      e=self.G[s][i]
      self.see[s]=i
      if e[0]>0 and self.level[s]<self.level[e[1]]:
        d=self.dfs(e[1],t,min(f,e[0]))
        if d!=0:
          self.G[s][i][0]-=d
          self.G[e[1]][e[2]][0]+=d
          return d
    return 0
  def maxflow(self,s,t):
    ans=0
    while True:
      self.bfs(s)
      if self.level[t]<0:
        return ans
      self.see=[0]*self.v
      d=self.dfs(s,t,self.inf)
      while d>0:
        ans+=d
        d=self.dfs(s,t,self.inf)
  def syokika(self,s,t):
    self.level=[-1]*self.v
    self.see=[0]*self.v
    for i in range(self.v):
      for j in range(len(self.G[i])):
        a,b,c=self.G[i][j]
        if b>i:
          self.G[i][j][0]=1
        else:
          self.G[i][j][0]=0
        if (i,b)==(s,t):
          self.G[i][j][0]=0
N,M,L=map(int,input().split())
A=list()
G=Dinic(N+M+2)
for i in range(L):
  a,b=map(int,input().split())
  A.append((a,N+b))
  G.add(a,N+b,1)
for i in range(N):
  G.add(0,i+1,1)
for i in range(M):
  G.add(N+i+1,N+M+1,1)
moto=G.G
aaaa=G.maxflow(0,N+M+1)
L=G.G
R=list()
K=list()
for i in range(1,N+1):
  for a,b,c in L[i]:
    if a==0:
      K.append([i,b])
S=set()
for n,m in K:
  G.syokika(n,m)
  a2=G.maxflow(0,N+M+1)
  if aaaa!=a2:
    S.add((n,m))
for i in A:
  if i in S:
    print("No")
  else:
    print("Yes")
0