結果

問題 No.19 ステージの選択
ユーザー roarisroaris
提出日時 2020-12-10 12:55:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 42 ms / 5,000 ms
コード長 621 bytes
コンパイル時間 223 ms
コンパイル使用メモリ 81,848 KB
実行使用メモリ 55,616 KB
最終ジャッジ日時 2023-10-20 00:41:29
合計ジャッジ時間 3,031 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
55,616 KB
testcase_01 AC 38 ms
55,612 KB
testcase_02 AC 38 ms
55,616 KB
testcase_03 AC 38 ms
55,616 KB
testcase_04 AC 39 ms
55,612 KB
testcase_05 AC 39 ms
55,612 KB
testcase_06 AC 38 ms
55,616 KB
testcase_07 AC 40 ms
55,616 KB
testcase_08 AC 42 ms
55,616 KB
testcase_09 AC 38 ms
55,616 KB
testcase_10 AC 37 ms
55,612 KB
testcase_11 AC 37 ms
55,612 KB
testcase_12 AC 38 ms
55,612 KB
testcase_13 AC 39 ms
55,612 KB
testcase_14 AC 38 ms
55,616 KB
testcase_15 AC 38 ms
55,612 KB
testcase_16 AC 37 ms
55,612 KB
testcase_17 AC 38 ms
55,612 KB
testcase_18 AC 39 ms
55,612 KB
testcase_19 AC 38 ms
55,616 KB
testcase_20 AC 39 ms
55,616 KB
testcase_21 AC 39 ms
55,616 KB
testcase_22 AC 39 ms
55,616 KB
testcase_23 AC 39 ms
55,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import *

def bfs(s, g):
    q = deque([s])
    dist = [-1]*N
    dist[s] = 0
    
    while q:
        v = q.popleft()
        
        for nv in G[v]:
            if dist[nv]==-1:
                dist[nv] = dist[v]+1
                q.append(nv)
    
    return dist[g]!=-1
    
N = int(input())
ans = 0.0
decr = []

for i in range(N):
    L, S = map(int, input().split())
    ans += L
    decr.append((L/2, S-1, i))

decr.sort(reverse=True)
G = [[] for _ in range(N)]

for d, i, j in decr:
    if not bfs(i, j):
        ans -= d
        G[j].append(i)

print(ans)
0