結果

問題 No.2565 はじめてのおつかい
ユーザー かもめのうでかもめのうで
提出日時 2023-12-02 20:02:20
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 677 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 87,296 KB
最終ジャッジ日時 2023-12-02 20:02:30
合計ジャッジ時間 9,067 ms
ジャッジサーバーID
(参考情報)
judge13 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 41 ms
55,480 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 41 ms
55,480 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 157 ms
85,440 KB
testcase_17 AC 87 ms
76,932 KB
testcase_18 AC 92 ms
79,028 KB
testcase_19 AC 154 ms
82,060 KB
testcase_20 AC 146 ms
81,780 KB
testcase_21 AC 144 ms
81,916 KB
testcase_22 AC 123 ms
79,884 KB
testcase_23 AC 118 ms
79,744 KB
testcase_24 AC 81 ms
76,676 KB
testcase_25 AC 144 ms
82,056 KB
testcase_26 AC 115 ms
79,452 KB
testcase_27 AC 146 ms
82,480 KB
testcase_28 AC 155 ms
81,912 KB
testcase_29 AC 166 ms
83,612 KB
testcase_30 AC 154 ms
83,044 KB
testcase_31 AC 149 ms
82,056 KB
testcase_32 AC 130 ms
79,592 KB
testcase_33 AC 149 ms
82,764 KB
testcase_34 AC 144 ms
81,216 KB
testcase_35 AC 157 ms
84,040 KB
testcase_36 AC 148 ms
82,632 KB
testcase_37 AC 114 ms
79,732 KB
testcase_38 AC 154 ms
81,220 KB
testcase_39 AC 130 ms
79,876 KB
testcase_40 AC 179 ms
83,476 KB
testcase_41 AC 168 ms
84,180 KB
testcase_42 AC 127 ms
79,176 KB
testcase_43 AC 139 ms
80,940 KB
testcase_44 AC 102 ms
77,716 KB
testcase_45 AC 89 ms
77,056 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

n, m = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(m):
    v, u = map(int, input().split())
    v -= 1
    u -= 1
    g[v].append(u)

def culc_dist(st: int, g: list):
    dist = [1<<60]*n
    q = deque()
    q.append(st)
    dist[st] = 0
    while q:
        v = q.popleft()
        for nv in g[v]:
            if dist[nv] == -1:
                dist[nv] = dist[v] + 1
                q.append(nv)
    return dist

dist1 = culc_dist(0, g)
dist2 = culc_dist(n-2, g)
dist3 = culc_dist(n-1, g)
ans1 = dist1[n-2]+dist2[n-1]+dist3[0]
ans2 = dist1[n-1]+dist3[n-2]+dist2[0]
ans = min(ans1, ans2)
print(ans if ans < 1<<60 else -1)
0