PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000066. Chu trình ngắn nhất qua các bit (Shortest Cycle)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Chu trình ngắn nhất qua các bit (Shortest Cycle)
Shortest Cycle
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Create an undirected graph on n given nonnegative integers; vertices i and j are adjacent exactly when their bitwise AND is nonzero. Find the length of the shortest simple cycle, or -1 if none exists.
Input
First n; then n nonnegative integers a_i.
Output
Print the number of edges of the shortest simple cycle, or -1.
Subtasks
- Subtask 1 (40 points): . Every array element is a nonnegative integer. The graph is the simple graph induced by the pairwise bitwise AND.
- Subtask 2 (60 points): . Every array element is a nonnegative integer. The graph is the simple graph induced by the pairwise bitwise AND.
Examples
Input
3
3 6 5
Output
3
Explanation
3&6=2, 6&5=4, 3&5=1. Every pair is adjacent, forming a triangle of length 3.