結果

問題 No.2565 はじめてのおつかい
ユーザー かもめのうでかもめのうで
提出日時 2023-12-02 20:02:20
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 677 bytes
コンパイル時間 361 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 88,064 KB
最終ジャッジ日時 2024-09-26 21:35:37
合計ジャッジ時間 8,348 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 42 ms
54,016 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 40 ms
53,504 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 135 ms
85,760 KB
testcase_17 AC 87 ms
77,312 KB
testcase_18 AC 91 ms
79,232 KB
testcase_19 AC 142 ms
82,432 KB
testcase_20 AC 131 ms
82,304 KB
testcase_21 AC 136 ms
82,560 KB
testcase_22 AC 113 ms
80,640 KB
testcase_23 AC 115 ms
79,872 KB
testcase_24 AC 87 ms
77,312 KB
testcase_25 AC 149 ms
82,560 KB
testcase_26 AC 110 ms
80,000 KB
testcase_27 AC 134 ms
82,688 KB
testcase_28 AC 143 ms
82,176 KB
testcase_29 AC 153 ms
84,224 KB
testcase_30 AC 144 ms
83,584 KB
testcase_31 AC 137 ms
82,560 KB
testcase_32 AC 114 ms
80,128 KB
testcase_33 AC 139 ms
82,944 KB
testcase_34 AC 134 ms
81,536 KB
testcase_35 AC 143 ms
84,608 KB
testcase_36 AC 136 ms
83,200 KB
testcase_37 AC 111 ms
80,256 KB
testcase_38 AC 136 ms
81,792 KB
testcase_39 AC 123 ms
80,384 KB
testcase_40 AC 153 ms
83,968 KB
testcase_41 AC 145 ms
84,736 KB
testcase_42 AC 110 ms
80,000 KB
testcase_43 AC 127 ms
81,664 KB
testcase_44 AC 100 ms
78,080 KB
testcase_45 AC 90 ms
77,696 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