結果

問題 No.416 旅行会社
ユーザー ciel
提出日時 2016-08-27 03:25:33
言語 PyPy2
(7.3.15)
結果
WA  
実行時間 -
コード長 651 bytes
コンパイル時間 404 ms
コンパイル使用メモリ 77,056 KB
実行使用メモリ 132,020 KB
最終ジャッジ日時 2024-11-08 18:38:55
合計ジャッジ時間 17,059 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 21
権限があれば一括ダウンロードができます

ソースコード

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