結果
問題 | No.1576 織姫と彦星 |
ユーザー |
![]() |
提出日時 | 2022-12-23 02:13:54 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 249 ms / 2,000 ms |
コード長 | 731 bytes |
コンパイル時間 | 252 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-11-18 03:52:09 |
合計ジャッジ時間 | 7,671 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 54 |
ソースコード
from collections import defaultdict, dequefrom itertools import combinationsdef main():_ = int(input())st, gl = map(int, input().split())a = [st] + list(map(int, input().split())) + [gl]edge = defaultdict(list)for u, v in combinations(a, 2):if bin(u ^ v).count('1') == 1:edge[u].append(v)edge[v].append(u)q = deque()q.append(st)dist = defaultdict(lambda: -1)dist[st] = 0while q:v = q.popleft()for i in edge[v]:if i == gl:exit(print(dist[v]))if dist[i] == -1:dist[i] = dist[v] + 1q.append(i)print(-1)if __name__ == "__main__":main()