Binary Search
시간 제한4초메모리 제한1024 MB
각 정점에 0 또는 1이 적힌 무방향 그래프에서 어떤 보행으로도 만들 수 없는 가장 짧은 이진 문자열의 길이를 구하고, 모든 문자열이 가능하면 infinity를 출력한다.
문제
You are given an undirected graph with vertices and edges. Each vertex has a number written on it. This number is either or . A walk is a sequence of vertices in the graph such that any two consecutive vertices are connected by an edge. We call a binary sequence walkable if there is a walk in the graph that satisfies .
In other words, a binary sequence is walkable if it is possible to obtain by walking in the graph and writing down the binary numbers in the order that they are visited. An example is visualized in Figure B.1.

Figure B.1: Illustration of Sample Input 1. Every binary sequence of length at most is walkable.
Your task is to find the length of a shortest binary sequence that is not walkable.
입력
The input consists of:
- One line with two integers and (, ), the number of vertices and the number of edges.
- One line with integers ( for each ), where is the number written on vertex .
- lines, each with two integers and (, ), denoting that the vertices and are connected by an edge. It is guaranteed that every pair of vertices is connected by at most one edge.
출력
If every binary sequence is walkable, output "infinity". Otherwise, output the length of a shortest binary sequence that is not walkable.