結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー ヒッキープログラミングするスレ GitHub ガチヒッキープログラミングするスレ GitHub ガチ
提出日時 2016-12-18 08:16:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 704 ms / 2,000 ms
コード長 984 bytes
コンパイル時間 343 ms
コンパイル使用メモリ 86,840 KB
実行使用メモリ 140,544 KB
最終ジャッジ日時 2023-08-21 00:35:38
合計ジャッジ時間 11,729 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,356 KB
testcase_01 AC 71 ms
71,172 KB
testcase_02 AC 72 ms
71,532 KB
testcase_03 AC 76 ms
71,060 KB
testcase_04 AC 71 ms
71,380 KB
testcase_05 AC 77 ms
71,116 KB
testcase_06 AC 77 ms
71,356 KB
testcase_07 AC 75 ms
71,280 KB
testcase_08 AC 76 ms
71,056 KB
testcase_09 AC 76 ms
71,188 KB
testcase_10 AC 77 ms
71,352 KB
testcase_11 AC 75 ms
71,204 KB
testcase_12 AC 76 ms
71,352 KB
testcase_13 AC 76 ms
71,208 KB
testcase_14 AC 136 ms
78,312 KB
testcase_15 AC 127 ms
78,048 KB
testcase_16 AC 127 ms
77,892 KB
testcase_17 AC 125 ms
77,992 KB
testcase_18 AC 123 ms
78,092 KB
testcase_19 AC 124 ms
77,988 KB
testcase_20 AC 124 ms
78,220 KB
testcase_21 AC 129 ms
78,112 KB
testcase_22 AC 125 ms
78,284 KB
testcase_23 AC 128 ms
78,168 KB
testcase_24 AC 679 ms
139,768 KB
testcase_25 AC 680 ms
140,000 KB
testcase_26 AC 704 ms
140,276 KB
testcase_27 AC 668 ms
140,136 KB
testcase_28 AC 670 ms
139,748 KB
testcase_29 AC 685 ms
139,584 KB
testcase_30 AC 703 ms
140,308 KB
testcase_31 AC 702 ms
140,544 KB
testcase_32 AC 704 ms
140,012 KB
testcase_33 AC 654 ms
140,444 KB
testcase_34 AC 238 ms
111,636 KB
testcase_35 AC 91 ms
75,176 KB
testcase_36 AC 71 ms
71,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())

r = [[] for _ in range(n)]
s = [[] for _ in range(n)]
x1 = [0] * n
c1 = [0] * n
x2 = [0] * n
c2 = [16000000] * n
cost = {}

def ky(a, b):
    return a * 100000 + b

for _ in range(m):
    a, b, c = map(int, input().split())
    r[a].append(b)
    s[b].append(a)
    cost[ky(a, b)] = c

tmp1 = [0]
while len(tmp1) > 0:
    tmp2 = []
    for a in tmp1:
        ca = c1[a]
        for b in r[a]:
            c1[b] = max(c1[b], ca + cost[ky(a, b)])
            x1[b] += 1
            if x1[b] == len(s[b]):
                tmp2.append(b)
    tmp1 = tmp2

c2[n - 1] = c1[n - 1]
tmp1 = [n - 1]
while len(tmp1) > 0:
    tmp2 = []
    for b in tmp1:
        cb = c2[b]
        for a in s[b]:
            c2[a] = min(c2[a], cb - cost[ky(a, b)])
            x2[a] += 1
            if x2[a] == len(r[a]):
                tmp2.append(a)
    tmp1 = tmp2

p = 0
for i in range(n):
    if c1[i] != c2[i]:
        p += 1

print('{0} {1}/{2}'.format(c1[n - 1], p, n))
0