結果

問題 No.19 ステージの選択
ユーザー ゆるくゆるく
提出日時 2014-11-20 02:34:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 906 bytes
コンパイル時間 468 ms
コンパイル使用メモリ 10,944 KB
実行使用メモリ 10,104 KB
最終ジャッジ日時 2023-08-30 21:54:21
合計ジャッジ時間 2,942 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
9,892 KB
testcase_01 AC 29 ms
10,084 KB
testcase_02 AC 29 ms
10,084 KB
testcase_03 AC 29 ms
10,004 KB
testcase_04 AC 31 ms
9,968 KB
testcase_05 AC 30 ms
10,040 KB
testcase_06 AC 30 ms
9,896 KB
testcase_07 AC 31 ms
10,036 KB
testcase_08 AC 32 ms
10,040 KB
testcase_09 AC 31 ms
10,104 KB
testcase_10 AC 28 ms
9,916 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 29 ms
9,924 KB
testcase_15 AC 29 ms
9,968 KB
testcase_16 AC 30 ms
10,016 KB
testcase_17 AC 28 ms
9,912 KB
testcase_18 AC 31 ms
9,944 KB
testcase_19 AC 29 ms
9,948 KB
testcase_20 AC 30 ms
9,892 KB
testcase_21 AC 29 ms
10,020 KB
testcase_22 AC 29 ms
9,920 KB
testcase_23 AC 30 ms
9,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy

n = int(input())
e = deque([[int(i) for i in input().split()] for i in range(n)])
e.appendleft([0,0])

v = [False] * (n + 1)
d = [False] * (n + 1)
def dfs(i, j):
  if d[e[i][1]]:
    return -1
  if i == j:
    return j
  if v[e[i][1]]:
    return -1
  v[i] = True
  ret = dfs(e[i][1], j)
  if ret == -1:
    return -1
  if e[i][0] < e[ret][0]:
    return i
  return ret

ans = 0
for i in range(1, n + 1):
  if d[i]:
    continue
  v = [False] * (n + 1)
  ret = dfs(e[i][1], i)
  if ret >= 0:
    ans += e[ret][0]
    d[ret] = True

for _ in range(1, n + 1):
  for i in range(1, n + 1):
    if d[e[i][1]] and not(d[i]):
      ans += e[i][0] / 2
      d[i] = True
print(ans)
0