Under construction

Still being built. Things may change

Binary Search

Time limit4sMemory limit1024 MB

Summary
Given an undirected graph with 0/1 labels on vertices, find the length of the shortest binary string that no walk can spell, or report infinity.
Level

Hard8 of 10

Topics
Graph, Dynamic programming, BFS
Solved
No attempts yet

Problem

You are given an undirected graph with nn vertices and mm edges. Each vertex vv has a number ava_v written on it, which is either 00 or 11.

A walk is a sequence of vertices v1v2…vkv_1v_2 \dots v_k in the graph such that any two consecutive vertices are connected by an edge. A binary sequence s=s1s2…sks = s_1s_2 \dots s_k is walkable if there is a walk v1v2…vkv_1v_2 \dots v_k with av1av2…avk=sa_{v_1} a_{v_2} \dots a_{v_k} = s.

In other words, a binary sequence is walkable if you can walk through the graph and write down the numbers of the visited vertices in order to get ss. Figure B.1 shows Sample Input 1, where every binary sequence of length at most 33 is walkable.

Find the length of a shortest binary sequence that is not walkable.

Input

The first line has two integers nn and mm (1≤n≤3⋅1051 \leq n \leq 3 \cdot 10^5, 0≤m≤3⋅1050 \leq m \leq 3 \cdot 10^5), the number of vertices and the number of edges.

The second line has nn integers a1,…,ana_1, \dots, a_n, where each ava_v is either 0 or 1.

Each of the next mm lines has two integers uu and vv (1≤u,v≤n1 \leq u, v \leq n, u≠vu \neq v), meaning vertices uu and vv are connected by an edge. Every pair of vertices is connected by at most one edge.

Output

If every binary sequence is walkable, print "infinity". Otherwise, print the length of a shortest binary sequence that is not walkable.

Examples3

  1. Example 1

    Input
    4 4
    0 0 1 1
    1 2
    1 3
    2 3
    3 4
    
    Expected output
    4
    
  2. Example 2

    Input
    6 7
    0 0 1 1 0 1
    1 2
    3 1
    1 4
    2 3
    4 2
    3 4
    5 6
    
    Expected output
    infinity
    
  3. Example 3

    Input
    1 0
    0
    
    Expected output
    1