結果

問題 No.241 出席番号(1)
ユーザー roarisroaris
提出日時 2019-12-06 11:23:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,215 bytes
コンパイル時間 466 ms
コンパイル使用メモリ 10,916 KB
実行使用メモリ 8,976 KB
最終ジャッジ日時 2023-08-24 19:48:16
合計ジャッジ時間 5,936 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 19 ms
8,568 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 18 ms
8,772 KB
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 24 ms
8,848 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)
from collections import defaultdict

def dfs(v, t, f, used):
    if v==t:
        return f
    
    used[v] = True
    
    for nv, cap in edges[v].items():
        if not used[nv] and cap>0:
            d = dfs(nv, t, min(f, cap), used)
            
            if d>0:
                edges[v][nv] -= d
                edges[nv][v] += d
                
                return d
    
    return 0

def max_flow(s, t):
    flow = 0
    
    while True:
        used = [False]*(2*N+2)
        f = dfs(s, t, 10**18, used)
        
        if f==0:
            return flow
        
        flow += f
        
N = int(input())
A = [int(input()) for _ in range(N)]
edges = defaultdict(dict)

for i in range(1, N+1):
    edges[0][i] = 1
    edges[i][0] = 0

for i in range(1, N+1):
    for j in range(N+1, 2*N+1):
        if j!=A[i-1]+N+1:
            edges[i][j] = 1
            edges[j][i] = 0

for i in range(N+1, 2*N+1):
    edges[i][2*N+1] = 1
    edges[2*N+1][i] = 0

f = max_flow(0, 2*N+1)

if f<N:
    print(-1)
    exit()

for i in range(1, N+1):
    for j in range(N+1, 2*N+1):
        if j in edges[i] and edges[i][j]==0:
            print(i-1, j-N-1)
            break
0