結果
問題 |
No.3263 違法な散歩道
|
ユーザー |
![]() |
提出日時 | 2025-09-13 19:28:44 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 301 ms / 2,000 ms |
コード長 | 763 bytes |
コンパイル時間 | 254 ms |
コンパイル使用メモリ | 82,296 KB |
実行使用メモリ | 109,188 KB |
最終ジャッジ日時 | 2025-09-13 19:28:54 |
合計ジャッジ時間 | 7,820 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
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 = 1 st = False while Q: while Q: x = Q.pop() 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: if y == N - 1: print(cnt) exit() Q2.append(y) cnt += 1 Q,Q2 = Q2,Q print(-1)