結果

問題 No.2565 はじめてのおつかい
ユーザー moharan627moharan627
提出日時 2023-12-02 15:47:43
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,715 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 136,252 KB
最終ジャッジ日時 2023-12-02 15:48:02
合計ジャッジ時間 16,401 ms
ジャッジサーバーID
(参考情報)
judge9 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
55,604 KB
testcase_01 AC 46 ms
55,604 KB
testcase_02 AC 43 ms
55,604 KB
testcase_03 AC 557 ms
136,252 KB
testcase_04 AC 267 ms
136,252 KB
testcase_05 AC 43 ms
55,604 KB
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 AC 236 ms
112,788 KB
testcase_17 AC 84 ms
81,860 KB
testcase_18 AC 108 ms
87,308 KB
testcase_19 AC 413 ms
109,552 KB
testcase_20 AC 432 ms
106,488 KB
testcase_21 AC 348 ms
106,020 KB
testcase_22 AC 147 ms
93,172 KB
testcase_23 AC 313 ms
96,340 KB
testcase_24 AC 60 ms
73,380 KB
testcase_25 AC 405 ms
106,412 KB
testcase_26 AC 272 ms
94,892 KB
testcase_27 AC 226 ms
104,164 KB
testcase_28 AC 372 ms
107,536 KB
testcase_29 AC 439 ms
116,112 KB
testcase_30 AC 232 ms
105,784 KB
testcase_31 WA -
testcase_32 AC 138 ms
92,004 KB
testcase_33 AC 221 ms
104,908 KB
testcase_34 WA -
testcase_35 AC 289 ms
114,888 KB
testcase_36 AC 387 ms
109,116 KB
testcase_37 AC 281 ms
95,664 KB
testcase_38 AC 213 ms
100,424 KB
testcase_39 AC 414 ms
100,052 KB
testcase_40 AC 278 ms
113,012 KB
testcase_41 AC 401 ms
118,380 KB
testcase_42 WA -
testcase_43 AC 232 ms
99,560 KB
testcase_44 AC 226 ms
89,652 KB
testcase_45 AC 86 ms
82,160 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 AC 42 ms
55,604 KB
testcase_52 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10**9 + 7
MOD2 = 998244353
from collections import defaultdict
def ceil(A,B):
    return -(-A//B)
import heapq
def dijkstra(edges: "List[List[(cost, to)]]", start_node: int) -> list:
    hq = []
    heapq.heapify(hq)
    # Set start info
    dist = [INF] * len(edges)
    heapq.heappush(hq, (0, start_node))
    dist[start_node] = 0
    # dijkstra
    while hq:
        # ------------------------------------------- タイミング1
        min_cost, now = heapq.heappop(hq)
        # ------------------------------------------- タイミング2
        if min_cost > dist[now]:
            continue
        for cost, next in edges[now]:
            if dist[next] > dist[now] + cost:
                dist[next] = dist[now] + cost
                heapq.heappush(hq, (dist[next], next))
            # --------------------------------------- タイミング3
    return dist
def solve():
    def II(): return int(sys.stdin.readline())
    def LI(): return list(map(int, sys.stdin.readline().split()))
    def LC(): return list(sys.stdin.readline().rstrip())
    def IC(): return [int(c) for c in sys.stdin.readline().rstrip()]
    def MI(): return map(int, sys.stdin.readline().split())
    N,M = MI()
    Edge = [[] for _ in range(4*N)]
    for i in range(M):
        U,V = MI()
        U-=1
        V-=1
        for i in range(4):
            Edge[i*N+U].append((1,i*N+V))
    Edge[N-2].append((0,2*N-2))
    Edge[N-1].append((0,3*N-1))
    Edge[2*-2].append((0,4*N-2))
    Edge[3*N-1].append((0,4*N - 1))
    Dist = dijkstra(Edge,0)
    #print(Dist)

    if(Dist[3*N]==INF):
        print(-1)
    else:
        print(Dist[3*N])
    return
solve()
0