結果

問題 No.2565 はじめてのおつかい
ユーザー K5h1n0K5h1n0
提出日時 2023-12-02 16:28:37
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 842 bytes
コンパイル時間 581 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 93,480 KB
最終ジャッジ日時 2023-12-02 16:28:46
合計ジャッジ時間 7,772 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 34 ms
55,604 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 34 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 112 ms
87,064 KB
testcase_17 AC 72 ms
77,312 KB
testcase_18 AC 75 ms
79,356 KB
testcase_19 AC 116 ms
83,964 KB
testcase_20 AC 115 ms
82,940 KB
testcase_21 AC 112 ms
83,068 KB
testcase_22 AC 116 ms
81,276 KB
testcase_23 AC 93 ms
81,276 KB
testcase_24 AC 65 ms
76,928 KB
testcase_25 AC 114 ms
83,068 KB
testcase_26 AC 96 ms
80,764 KB
testcase_27 AC 116 ms
84,092 KB
testcase_28 AC 125 ms
83,708 KB
testcase_29 AC 134 ms
86,752 KB
testcase_30 AC 121 ms
85,288 KB
testcase_31 AC 117 ms
83,836 KB
testcase_32 AC 112 ms
80,764 KB
testcase_33 AC 118 ms
84,348 KB
testcase_34 AC 113 ms
82,428 KB
testcase_35 AC 121 ms
85,288 KB
testcase_36 AC 116 ms
83,448 KB
testcase_37 AC 96 ms
81,276 KB
testcase_38 AC 113 ms
83,068 KB
testcase_39 AC 105 ms
81,276 KB
testcase_40 AC 124 ms
86,768 KB
testcase_41 AC 136 ms
86,448 KB
testcase_42 AC 97 ms
80,636 KB
testcase_43 AC 110 ms
81,788 KB
testcase_44 AC 83 ms
78,844 KB
testcase_45 AC 72 ms
77,436 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 defaultdict,deque

n,m = map(int,input().split())
d = defaultdict(list)
for _ in range(m):
    a,b = map(int,input().split())
    d[a].append(b)
from1 = [float("INF")]*(n+1)
fromnminus1 = [float("INF")]*(n+1)
fromn = [float("INF")]*(n+1)

def bfs(start,result):
    global d
    visited = [False]*(n+1)
    q = deque()
    visited[start] = True
    cnt = 0
    q.append((start,cnt))
    while q:
        nowv,nowcnt = q.popleft()
        result[nowv] = nowcnt
        for nextv in d[nowv]:
            if visited[nextv] == False:
                visited[nextv] = True
                q.append((nextv,nowcnt+1))
    return result

route1 = from1[n-1] + fromnminus1[n] + fromn[1]
route2 = from1[n] + fromn[n-1] + fromnminus1[1]
result = min(route1,route2)
if result == float("inf"):
    print(-1)
else:
    print(result)
0