結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
tomarint2
|
| 提出日時 | 2019-03-22 22:38:08 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,630 bytes |
| コンパイル時間 | 140 ms |
| コンパイル使用メモリ | 82,148 KB |
| 実行使用メモリ | 849,076 KB |
| 最終ジャッジ日時 | 2024-09-19 06:04:05 |
| 合計ジャッジ時間 | 3,993 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 11 MLE * 1 -- * 14 |
ソースコード
import copy
import collections
N,M=map(int,input().split())
d=[[0 for j in range(N+1)] for i in range(N+1)]
for i in range(M):
a,b,c=map(int,input().split())
d[a][b]=d[b][a]=c
inf=1<<60
#現在地、ゴール、コスト、チケット利用回数、履歴
def solve0(location, goal, cost, ticket, history):
cost2 = inf
#print('solve', location, goal, cost, ticket)
history2 = copy.copy(history)
history2.add(location)
if location==goal:
return cost
for i in range(1,N+1):
if d[location][i]==0:
continue
if i in history2:
continue
cost2=min(cost2,solve(i,goal,cost+d[location][i],ticket,history2))
if ticket==0:
cost2=min(cost2,solve(i,goal,cost,1,history2))
return cost2
def solve(location, goal, cost, ticket):
q = collections.deque()
q.append((location, cost, ticket))
cost2 = inf
try:
while True:
location, cost, ticket = q.popleft()
#print('solve', location, goal, cost, ticket)
if location==goal:
cost2=min(cost2,cost)
continue
if cost >= cost2:
continue
for i in range(1,N+1):
if d[location][i]==0:
continue
q.append((i, cost+d[location][i], ticket))
if ticket==0:
q.append((i, cost, 1))
except IndexError:
pass
return cost2
for i in range(1,N+1):
#ans=solve(1, i, 0, 0, set()) + solve(1, i, 0, 1, set())
ans=solve(1, i, 0, 0) + solve(1, i, 0, 1)
print(ans)
tomarint2