CF1205B Shortest Cycle

题目描述

给定 $n$ 个整数 $a_1,\,a_2,\,\cdots,a_n$,考虑一张含有 $n$ 个节点的图,对于任意 $i\ne j$,若 $a_i\;\text{and}\;a_j\ne 0$,则节点 $i,j$ 连通,其中 $\text{and}$ 表示按位与运算 你现在需要求出该图最小环的大小,或确定其不存在环。

输入格式

第一行一个整数 $n$ $(1 \le n \le 10^5)$。 第二行包含 $n$ 个整数,第 $i$ 个数表示 $a_i$ $(0 \le a_i \le 10^{18})$。

输出格式

仅一个数,表示最小环的大小,若不存在环,则输出 $-1$。

说明/提示

In the first example, the shortest cycle is $ (9, 3, 6, 28) $ . In the second example, the shortest cycle is $ (5, 12, 9) $ . The graph has no cycles in the third example.