結果
| 問題 |
No.468 役に立つ競技プログラミング実践編
|
| ユーザー |
|
| 提出日時 | 2016-12-18 10:47:05 |
| 言語 | PyPy2 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,107 bytes |
| コンパイル時間 | 1,981 ms |
| コンパイル使用メモリ | 76,680 KB |
| 実行使用メモリ | 294,668 KB |
| 最終ジャッジ日時 | 2024-12-14 08:03:37 |
| 合計ジャッジ時間 | 41,461 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 21 TLE * 10 |
| other | AC * 6 |
ソースコード
#!/usr/bin/python2
# -*- coding: utf-8 -*-
# †
from heapq import heappush, heappop
from collections import namedtuple
edge = namedtuple('edge', 'to, cost')
n, m = map(int, raw_input().split())
G0 = [[] for i in range(n)]
rG = [[] for i in range(n)]
for _ in xrange(m):
a, b, c = map(int, raw_input().split())
G0[a].append(edge(b, c))
rG[b].append(edge(a, c))
cost0 = [-1] * n # cost0[n]
cost0[0] = 0
que0 = []
heappush(que0, [0, 0])
while len(que0):
c, v = heappop(que0)
if c < cost0[v]:
continue
for e in G0[v]:
if cost0[e.to] < cost0[v] + e.cost:
cost0[e.to] = cost0[v] + e.cost
heappush(que0, [cost0[e.to], e.to])
rcost = [-1] * n # rcost[n]
rcost[n-1] = 0
rq = []
heappush(rq, [0, n-1])
while len(rq):
c, v = heappop(rq)
if c < rcost[v]:
continue
for e in rG[v]:
if rcost[e.to] < rcost[v] + e.cost:
rcost[e.to] = rcost[v] + e.cost
heappush(rq, [rcost[e.to], e.to])
days = cost0[n-1]
cnt = sum(cost0[i] != days - rcost[i] for i in xrange(n))
print '{} {}/{}'.format(days, cnt, n)