結果
問題 | No.1565 Union |
ユーザー |
![]() |
提出日時 | 2021-06-26 13:27:00 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 443 ms / 2,000 ms |
コード長 | 459 bytes |
コンパイル時間 | 443 ms |
コンパイル使用メモリ | 82,324 KB |
実行使用メモリ | 99,916 KB |
最終ジャッジ日時 | 2024-12-20 18:47:00 |
合計ジャッジ時間 | 8,040 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
from collections import dequen,m=map(int,input().split())path=[[] for _ in range(n)]for i in range(m):a,b=map(int,input().split())path[a-1].append(b-1)path[b-1].append(a-1)ans=[10**9]*nans[0]=0queue=deque()queue.append(0)while len(queue)!=0:num=queue.popleft()for i in path[num]:if ans[i]>ans[num]+1:ans[i]=ans[num]+1queue.append(i)if ans[-1]==10**9:print(-1)else:print(ans[-1])