結果
| 問題 |
No.1565 Union
|
| コンテスト | |
| ユーザー |
H20
|
| 提出日時 | 2021-06-27 16:24:39 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 431 bytes |
| コンパイル時間 | 278 ms |
| コンパイル使用メモリ | 82,048 KB |
| 実行使用メモリ | 100,224 KB |
| 最終ジャッジ日時 | 2024-06-25 11:50:42 |
| 合計ジャッジ時間 | 7,722 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 WA * 8 |
ソースコード
import collections
N,M = map(int, input().split())
L = [[] for _ in range(N+1)]
for i in range(M):
a,b = map(int, input().split())
L[b].append(a)
L[a].append(b)
PASS = [False]*(N+1)
d = collections.deque()
d.append((1,0))
while len(d):
p,cnt=d.pop()
if p==N:
print(cnt)
exit()
for n in L[p]:
if PASS[n]==False:
PASS[n]=True
d.append((n,cnt+1))
print(-1)
H20