結果

問題 No.3263 違法な散歩道
ユーザー ntuda
提出日時 2025-09-13 15:47:11
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 795 bytes
コンパイル時間 437 ms
コンパイル使用メモリ 82,568 KB
実行使用メモリ 109,376 KB
最終ジャッジ日時 2025-09-13 15:47:21
合計ジャッジ時間 9,424 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M = map(int,input().split())
UV = [list(map(int,input().split())) for _ in range(M)]
K = int(input())
if K:
    A = set([i-1 for i in list(map(int,input().split()))])
else:
    A = []

E = [[] for _ in range(N)]
for u, v in UV:
    u -= 1
    v -= 1
    E[u].append(v)
    E[v].append(u)
V = [5] * N
V[0] = 0
Q = [0]
Q2 = []
cnt = 0
st = False
while Q:
    while Q:
        x = Q.pop()
        if x == N - 1:
            st = False
            break
        for y in E[x]:
            if y in A:
                tmp = V[x] + 1
            else:
                tmp = 0
            if V[y] > tmp:
                V[y] = tmp
                if V[y] < 5:
                    Q2.append(y)
    if st:
        break
    Q,Q2 = Q2,Q
    cnt += 1
if V[N-1] < 5:
    print(cnt - 1)
else:
    print(-1)
0