結果

問題 No.416 旅行会社
ユーザー cielciel
提出日時 2016-08-27 03:26:27
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 1,550 ms / 4,000 ms
コード長 633 bytes
コンパイル時間 2,168 ms
コンパイル使用メモリ 77,604 KB
実行使用メモリ 132,496 KB
最終ジャッジ日時 2023-08-21 09:50:50
合計ジャッジ時間 17,025 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 297 ms
117,744 KB
testcase_01 AC 81 ms
78,224 KB
testcase_02 AC 81 ms
78,108 KB
testcase_03 AC 80 ms
78,228 KB
testcase_04 AC 82 ms
77,972 KB
testcase_05 AC 82 ms
77,976 KB
testcase_06 AC 85 ms
77,972 KB
testcase_07 AC 113 ms
80,156 KB
testcase_08 AC 189 ms
82,928 KB
testcase_09 AC 247 ms
86,720 KB
testcase_10 AC 465 ms
118,272 KB
testcase_11 AC 458 ms
118,380 KB
testcase_12 AC 450 ms
118,260 KB
testcase_13 AC 296 ms
117,932 KB
testcase_14 AC 1,528 ms
131,968 KB
testcase_15 AC 1,476 ms
131,860 KB
testcase_16 AC 1,424 ms
131,516 KB
testcase_17 AC 1,503 ms
132,460 KB
testcase_18 AC 1,550 ms
132,496 KB
testcase_19 AC 1,161 ms
126,812 KB
testcase_20 AC 1,199 ms
128,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python
from collections import defaultdict
import sys,heapq

H=defaultdict(dict)
N,M,Q=map(int,sys.stdin.readline().split())
for i in range(M):
	x,y=map(int,sys.stdin.readline().split())
	x-=1;y-=1
	H[x][y]=H[y][x]=0
for i in range(Q):
	x,y=map(int,sys.stdin.readline().split())
	x-=1;y-=1
	H[x][y]=H[y][x]=Q-i

#dijkstra-like
A=[0]+[-1]*(N-1)
q=[[0,0]]
while q:
	cost1,src=heapq.heappop(q)
	for dst,cost2 in H[src].items():
		cost=max(cost1,cost2)
		if A[dst]<0 or cost<A[dst]:
			A[dst]=cost
			heapq.heappush(q,[cost,dst])

for i in range(1,N):
	if A[i]<0:
		print(0)
	elif A[i]==0:
		print(-1)
	else:
		print(Q-A[i]+1)
0