結果

問題 No.2565 はじめてのおつかい
ユーザー loop0919loop0919
提出日時 2023-09-21 22:12:30
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,085 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 86,900 KB
実行使用メモリ 89,908 KB
最終ジャッジ日時 2023-09-21 22:12:44
合計ジャッジ時間 12,565 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 94 ms
71,296 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 96 ms
71,536 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 204 ms
86,504 KB
testcase_17 AC 140 ms
79,228 KB
testcase_18 AC 143 ms
81,516 KB
testcase_19 AC 198 ms
84,232 KB
testcase_20 AC 186 ms
82,956 KB
testcase_21 AC 182 ms
83,348 KB
testcase_22 AC 155 ms
81,372 KB
testcase_23 AC 178 ms
81,960 KB
testcase_24 AC 129 ms
77,752 KB
testcase_25 AC 184 ms
83,448 KB
testcase_26 AC 174 ms
81,644 KB
testcase_27 AC 197 ms
83,824 KB
testcase_28 AC 208 ms
83,872 KB
testcase_29 AC 223 ms
85,572 KB
testcase_30 AC 198 ms
85,228 KB
testcase_31 AC 190 ms
83,396 KB
testcase_32 AC 157 ms
80,616 KB
testcase_33 AC 191 ms
83,720 KB
testcase_34 AC 204 ms
82,556 KB
testcase_35 AC 200 ms
86,276 KB
testcase_36 AC 184 ms
84,028 KB
testcase_37 AC 159 ms
80,844 KB
testcase_38 AC 187 ms
82,492 KB
testcase_39 AC 174 ms
81,832 KB
testcase_40 AC 223 ms
85,732 KB
testcase_41 AC 209 ms
86,352 KB
testcase_42 AC 163 ms
81,288 KB
testcase_43 AC 181 ms
82,192 KB
testcase_44 AC 151 ms
79,808 KB
testcase_45 AC 138 ms
78,960 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

# import系 ---
from collections import defaultdict

# 入力用 ---
INT = lambda: int(input())
MI = lambda: map(int, input().split())
MI_DEC = lambda: map(lambda x: int(x) - 1, input().split())
LI = lambda: list(map(int, input().split()))
LI_DEC = lambda: list(map(lambda x: int(x) - 1, input().split()))
LS = lambda: list(input())
LSS = lambda: input().split()

# コード ---
import sys
sys.setrecursionlimit(10**6)
from collections import deque

INF = 1 << 60

N, M = map(int, input().split())

graph = [[] for _ in range(N)]

for _ in range(M):
    u, v = map(int, input().split())
    u -= 1; v -= 1
    graph[u].append(v)

dist = {
    0: [INF for _ in range(N)],
    N-2: [INF for _ in range(N)],
    N-1: [INF for _ in range(N)]
}

def dfs(start, now, dist):
    
    dist[start][now] = dist
    
    for next in graph[now]:
        if dist[start][next] < INF:
            continue
        dfs(start, next, dist + 1)

ans = min(
    dist[0][N-2] + dist[N-2][N-1] + dist[N-1][0],
    dist[0][N-1] + dist[N-1][N-2] + dist[N-2][0]
)

if ans < INF:
	print(ans)
else:
	print(-1)

0