結果

問題 No.416 旅行会社
ユーザー cielciel
提出日時 2016-08-27 03:25:33
言語 PyPy2
(7.3.15)
結果
WA  
実行時間 -
コード長 651 bytes
コンパイル時間 174 ms
コンパイル使用メモリ 76,712 KB
実行使用メモリ 131,892 KB
最終ジャッジ日時 2024-04-26 05:50:10
合計ジャッジ時間 18,277 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

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)
	print(cost1,src)
	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