結果

問題 No.241 出席番号(1)
ユーザー noriocnorioc
提出日時 2021-07-13 09:02:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,080 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 11,032 KB
実行使用メモリ 8,396 KB
最終ジャッジ日時 2023-09-15 06:48:29
合計ジャッジ時間 3,778 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 16 ms
7,716 KB
testcase_10 AC 16 ms
7,844 KB
testcase_11 AC 16 ms
7,840 KB
testcase_12 AC 16 ms
7,712 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 16 ms
7,792 KB
testcase_17 RE -
testcase_18 AC 16 ms
7,768 KB
testcase_19 AC 16 ms
7,792 KB
testcase_20 AC 16 ms
7,772 KB
testcase_21 AC 17 ms
7,760 KB
testcase_22 AC 16 ms
7,852 KB
testcase_23 AC 16 ms
7,856 KB
testcase_24 AC 17 ms
8,148 KB
testcase_25 RE -
testcase_26 AC 17 ms
8,204 KB
testcase_27 AC 17 ms
8,396 KB
testcase_28 AC 16 ms
7,900 KB
testcase_29 AC 17 ms
8,260 KB
testcase_30 AC 17 ms
7,824 KB
testcase_31 AC 17 ms
7,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#
# 二部グラフの最大マッチング
#

import sys
sys.setrecursionlimit(10 ** 6)

def max_bipartite_matching(g):
    def rec(p, left, right, used) -> bool:
        for i in range(len(right)):
            if g[p][i] and right[i] == -1:
                left[p] = i
                right[i] = p
                return True
        for i in range(len(right)):
            if g[p][i] and not used[i]:
                used[i] = True
                if rec(right[i], left, right, used):
                    left[p] = i
                    right[i] = p
                    return True
        return False

    left = [-1] * len(g)
    right = [-1] * len(g[0])
    cnt = 0
    for i in range(len(left)):
        used = [False] * len(left)
        if rec(i, left, right, used):
            cnt += 1
    return cnt, left, right


N = int(input())
a = [int(input()) for _ in range(N)]

g = []
for i in range(N):
    g.append([True] * N)
    g[i][a[i]] = False

cnt, left, right = max_bipartite_matching(g)
if cnt == len(left):
    for e in left:
        print(e)
else:
    print(-1)
0