結果

問題 No.2565 はじめてのおつかい
ユーザー lloyzlloyz
提出日時 2023-12-12 07:28:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 274 ms / 2,000 ms
コード長 706 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 101,208 KB
最終ジャッジ日時 2023-12-12 07:29:13
合計ジャッジ時間 13,989 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
55,604 KB
testcase_01 AC 38 ms
55,604 KB
testcase_02 AC 36 ms
55,604 KB
testcase_03 AC 218 ms
101,208 KB
testcase_04 AC 185 ms
101,204 KB
testcase_05 AC 39 ms
55,604 KB
testcase_06 AC 181 ms
82,556 KB
testcase_07 AC 142 ms
79,876 KB
testcase_08 AC 148 ms
81,660 KB
testcase_09 AC 194 ms
81,788 KB
testcase_10 AC 165 ms
83,068 KB
testcase_11 AC 274 ms
93,064 KB
testcase_12 AC 103 ms
77,444 KB
testcase_13 AC 158 ms
81,276 KB
testcase_14 AC 228 ms
87,292 KB
testcase_15 AC 235 ms
85,244 KB
testcase_16 AC 150 ms
94,600 KB
testcase_17 AC 84 ms
77,308 KB
testcase_18 AC 96 ms
81,404 KB
testcase_19 AC 225 ms
90,620 KB
testcase_20 AC 213 ms
89,084 KB
testcase_21 AC 204 ms
89,212 KB
testcase_22 AC 125 ms
82,812 KB
testcase_23 AC 187 ms
84,652 KB
testcase_24 AC 79 ms
76,932 KB
testcase_25 AC 214 ms
90,620 KB
testcase_26 AC 161 ms
83,068 KB
testcase_27 AC 135 ms
85,756 KB
testcase_28 AC 214 ms
90,620 KB
testcase_29 AC 268 ms
94,164 KB
testcase_30 AC 153 ms
89,620 KB
testcase_31 AC 234 ms
91,260 KB
testcase_32 AC 111 ms
82,556 KB
testcase_33 AC 142 ms
88,956 KB
testcase_34 AC 215 ms
87,164 KB
testcase_35 AC 147 ms
89,484 KB
testcase_36 AC 221 ms
90,748 KB
testcase_37 AC 169 ms
84,860 KB
testcase_38 AC 157 ms
84,604 KB
testcase_39 AC 203 ms
86,012 KB
testcase_40 AC 155 ms
89,060 KB
testcase_41 AC 229 ms
94,756 KB
testcase_42 AC 208 ms
83,708 KB
testcase_43 AC 132 ms
83,964 KB
testcase_44 AC 148 ms
81,788 KB
testcase_45 AC 88 ms
77,564 KB
testcase_46 AC 235 ms
85,744 KB
testcase_47 AC 185 ms
79,364 KB
testcase_48 AC 190 ms
81,532 KB
testcase_49 AC 119 ms
77,572 KB
testcase_50 AC 158 ms
80,004 KB
testcase_51 AC 39 ms
55,604 KB
testcase_52 AC 134 ms
77,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict, deque

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

INF = 10**18
DP = [[INF for _ in range(1 << 2)] for _ in range(n)]
DP[0][0] = 0
Que = deque([(0, 0)])
while Que:
    cp, cbit = Que.popleft()
    cc = DP[cp][cbit]
    nc = cc + 1
    for np in G[cp]:
        if np == n - 2:
            nbit = cbit | 1
        elif np == n - 1:
            nbit = cbit | (1 << 1)
        else:
            nbit = cbit
        if nc >= DP[np][nbit]:
            continue
        DP[np][nbit] = nc
        Que.append((np, nbit))
if DP[0][-1] == INF:
    print(-1)
else:
    print(DP[0][-1])
0