結果

問題 No.19 ステージの選択
ユーザー szkhtsszkhts
提出日時 2022-11-06 08:42:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 795 bytes
コンパイル時間 845 ms
コンパイル使用メモリ 10,856 KB
実行使用メモリ 8,004 KB
最終ジャッジ日時 2023-09-27 05:43:34
合計ジャッジ時間 3,463 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,776 KB
testcase_01 AC 14 ms
8,000 KB
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 15 ms
7,864 KB
testcase_12 AC 15 ms
7,804 KB
testcase_13 AC 14 ms
7,860 KB
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 -
権限があれば一括ダウンロードができます

ソースコード

diff #

dist = [[False] * 100] * 100

N = int(input())
L = []
S = []
ans = 0

for i in range(N):
    ls = input().split()
    L.append(int(ls[0]))
    S.append(int(ls[1]) - 1)
    dist[i][S[i]] = True
    dist[i][i] = True
    ans += L[i]

for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] |= (dist[i][k] & dist[k][j])

for i in range(N):
    flag = True
    for j in range(i):
        if dist[i][j] and dist[j][i]:
            flag = False

    if not flag:
        continue

    for j in range(N):
        if dist[i][j] and not dist[j][i]:
            flag = False

    if not flag:
        continue

    mincost = 999
    for j in range(i, N):
        if dist[i][j] and dist[j][i]:
            mincost = min(mincost, L[j])

    ans += mincost

print(ans / 2)
0