提出 #5679332


ソースコード 拡げる

N,G,E = map(int,input().split())
P = [int(x) for x in input().split()]
AB = [[int(x) for x in input().split()] for _ in range(E)]


graph = [[0]*(N+1) for _ in range(N+1)]
for a,b in AB:
  graph[a][b] = 1
  graph[b][a] = 1
for p in P:
  graph[p][N] = 1


def find_path(graph,v,flow,visited):
  visited[v] = True
  if v == N:
    return [N],flow
  for w in range(N+1):
    f = graph[v][w]
    if f and not visited[w]:
      p,f = find_path(graph,w,min(flow,f),visited)
      if p is None:
        continue
      return p+[v],f
  return None,None

INF = 10**18

def max_flow(graph):
  visited = [False]*(N+1)
  p,f = find_path(graph,0,INF,visited)
  if p is None:
    return 0
  v = 0
  for w in p[::-1][1:]:
    # 残capに更新
    graph[v][w] -= 1
    graph[w][v] += 1
    v = w
  return f + max_flow(graph)

answer = max_flow(graph)
print(answer)

提出情報

提出日時
問題 D - 浮気予防
ユーザ maspy
言語 Python (3.4.3)
得点 100
コード長 893 Byte
結果 AC
実行時間 88 ms
メモリ 3956 KiB

ジャッジ結果

セット名 part All
得点 / 配点 99 / 99 1 / 1
結果
AC × 27
AC × 61
セット名 テストケース
part test_01_AB.txt, test_02_AB.txt, test_03_AB.txt, test_04_AB.txt, test_05_AB.txt, test_06_AB.txt, test_07_AB.txt, test_08_AB.txt, test_09_AB.txt, test_10_AB.txt, test_11_AB.txt, test_12_AB.txt, test_13_AB.txt, test_14_AB.txt, test_15_AB.txt, test_16_AB.txt, test_17_AB.txt, test_18_AB.txt, test_19_AB.txt, test_20_AB.txt, test_21_AB.txt, test_22_AB.txt, test_23_AB.txt, test_24_AB.txt, test_25_AB.txt, test_41_AB.txt, test_47_AB.txt
All sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt, test_01_AB.txt, test_02_AB.txt, test_03_AB.txt, test_04_AB.txt, test_05_AB.txt, test_06_AB.txt, test_07_AB.txt, test_08_AB.txt, test_09_AB.txt, test_10_AB.txt, test_11_AB.txt, test_12_AB.txt, test_13_AB.txt, test_14_AB.txt, test_15_AB.txt, test_16_AB.txt, test_17_AB.txt, test_18_AB.txt, test_19_AB.txt, test_20_AB.txt, test_21_AB.txt, test_22_AB.txt, test_23_AB.txt, test_24_AB.txt, test_25_AB.txt, test_26_A.txt, test_27_A.txt, test_28_A.txt, test_29_A.txt, test_30_A.txt, test_31_A.txt, test_32_A.txt, test_33_A.txt, test_34_A.txt, test_35_A.txt, test_36_A.txt, test_37_A.txt, test_38_A.txt, test_39_A.txt, test_40_A.txt, test_41_AB.txt, test_42_A.txt, test_43_A.txt, test_44_A.txt, test_45_A.txt, test_46_A.txt, test_47_AB.txt, test_48_A.txt, test_49_A.txt, test_50_A.txt, test_51_A.txt
ケース名 結果 実行時間 メモリ
sample_01.txt AC 17 ms 3064 KiB
sample_02.txt AC 17 ms 3064 KiB
sample_03.txt AC 17 ms 3064 KiB
sample_04.txt AC 17 ms 3064 KiB
sample_05.txt AC 17 ms 3064 KiB
test_01_AB.txt AC 17 ms 3064 KiB
test_02_AB.txt AC 17 ms 3064 KiB
test_03_AB.txt AC 17 ms 3064 KiB
test_04_AB.txt AC 17 ms 3064 KiB
test_05_AB.txt AC 17 ms 3188 KiB
test_06_AB.txt AC 17 ms 3064 KiB
test_07_AB.txt AC 17 ms 3064 KiB
test_08_AB.txt AC 17 ms 3064 KiB
test_09_AB.txt AC 17 ms 3064 KiB
test_10_AB.txt AC 17 ms 3188 KiB
test_11_AB.txt AC 17 ms 3064 KiB
test_12_AB.txt AC 17 ms 3064 KiB
test_13_AB.txt AC 17 ms 3064 KiB
test_14_AB.txt AC 17 ms 3064 KiB
test_15_AB.txt AC 17 ms 3064 KiB
test_16_AB.txt AC 17 ms 3064 KiB
test_17_AB.txt AC 18 ms 3064 KiB
test_18_AB.txt AC 17 ms 3064 KiB
test_19_AB.txt AC 17 ms 3064 KiB
test_20_AB.txt AC 17 ms 3064 KiB
test_21_AB.txt AC 17 ms 3064 KiB
test_22_AB.txt AC 17 ms 3064 KiB
test_23_AB.txt AC 17 ms 3064 KiB
test_24_AB.txt AC 17 ms 3064 KiB
test_25_AB.txt AC 17 ms 3064 KiB
test_26_A.txt AC 88 ms 3956 KiB
test_27_A.txt AC 72 ms 3828 KiB
test_28_A.txt AC 66 ms 3828 KiB
test_29_A.txt AC 53 ms 3828 KiB
test_30_A.txt AC 37 ms 3700 KiB
test_31_A.txt AC 65 ms 3828 KiB
test_32_A.txt AC 22 ms 3188 KiB
test_33_A.txt AC 28 ms 3316 KiB
test_34_A.txt AC 20 ms 3064 KiB
test_35_A.txt AC 26 ms 3188 KiB
test_36_A.txt AC 22 ms 3188 KiB
test_37_A.txt AC 35 ms 3316 KiB
test_38_A.txt AC 17 ms 3064 KiB
test_39_A.txt AC 17 ms 3064 KiB
test_40_A.txt AC 17 ms 3064 KiB
test_41_AB.txt AC 17 ms 3064 KiB
test_42_A.txt AC 32 ms 3316 KiB
test_43_A.txt AC 17 ms 3064 KiB
test_44_A.txt AC 26 ms 3188 KiB
test_45_A.txt AC 18 ms 3064 KiB
test_46_A.txt AC 18 ms 3064 KiB
test_47_AB.txt AC 17 ms 3064 KiB
test_48_A.txt AC 18 ms 3064 KiB
test_49_A.txt AC 18 ms 3064 KiB
test_50_A.txt AC 18 ms 3064 KiB
test_51_A.txt AC 17 ms 3064 KiB