結果
問題 | No.1565 Union |
ユーザー |
|
提出日時 | 2021-06-26 14:51:36 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 440 bytes |
コンパイル時間 | 582 ms |
コンパイル使用メモリ | 82,444 KB |
実行使用メモリ | 101,100 KB |
最終ジャッジ日時 | 2024-06-25 10:38:42 |
合計ジャッジ時間 | 8,734 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 2 |
other | AC * 8 WA * 19 |
ソースコード
from collections import dequen,m = map(int,input().split())e = [[] for i in range(n)]for _ in range(m):a,b = [int(x)-1 for x in input().split()]e[a].append(b)e[b].append(a)dis = [n+1]*ndis[0] = 0q = deque([0])while q:now = q.popleft()for nex in e[now]:if dis[nex] > dis[now]+1:q.append(nex)dis[nex] = dis[now]+1if dis[-1] == n+1:print(-1)else:print(m-dis[-1])