結果
| 問題 |
No.3263 違法な散歩道
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-09-06 14:27:23 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 850 bytes |
| コンパイル時間 | 361 ms |
| コンパイル使用メモリ | 82,380 KB |
| 実行使用メモリ | 103,092 KB |
| 最終ジャッジ日時 | 2025-09-06 14:27:35 |
| 合計ジャッジ時間 | 8,723 ms |
|
ジャッジサーバーID (参考情報) |
judge / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | RE * 28 |
ソースコード
import sys
sys.setrecursionlimit(10**5)
import pypyjit
pypyjit.set_param('max_unroll_recursion=-1')
N,M=map(int,input().split())
G=[[] for _ in range(N+1)]
for _ in range(M):
U,V=map(int,input().split())
G[U].append(V)
G[V].append(U)
K=int(input())
A=set()
if K:A=set(map(int,input().split()))
ans=1<<30
def dfs(now,step,cnt,used:set,branch:list):
global ans
if now==N:
ans=min(ans,step)
return
if now not in A:
cnt=0
for i in branch:
used.remove(i)
if len(G[now])>=3:branch.append(now)
for nxt in G[now]:
if nxt in used:continue
if nxt in A:
if cnt==4:return
else:dfs(nxt,step+1,cnt+1,used|{nxt},branch[:])
else:
dfs(nxt,step+1,cnt,used|{nxt},branch[:])
dfs(1,0,0,{1},[])
if ans==1<<30:print(-1)
else:print(ans)