#P13740. [NWERC 2024] Binary Search

[NWERC 2024] Binary Search

题目描述

You are given an undirected graph with nn vertices and mm edges. Each vertex vv has a number ava_v written on it. This number is either 00 or 11. A walk is a sequence v1v2vkv_1v_2 \dots v_k of vertices in the graph such that any two consecutive vertices are connected by an edge. We call a binary sequence

s=s1s2sks = s_1s_2 \dots s_k

walkable if there is a walk v1v2vkv_1v_2 \dots v_k in the graph that satisfies av1av2avk=sa_{v_1} a_{v_2} \dots a_{v_k} = s.

In other words, a binary sequence is walkable if it is possible to obtain ss 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.

:::align{center}

Figure B.1: Illustration of Sample Input 1. Every binary sequence of length at most 3 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 nn and mm (1n31051 \leq n \leq 3 \cdot 10^5, 0m31050 \leq m \leq 3 \cdot 10^5), the number of vertices and the number of edges.
  • One line with nn integers a1,,ana_1,\dots, a_n (av{0,1}a_v \in \{0, 1\} for each vv), where ava_v is the number written on vertex vv.
  • mm lines, each with two integers uu and vv (1u,vn1 \leq u,v \leq n, uvu \neq v), denoting that the vertices uu and vv 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\texttt{infinity}". Otherwise, output the length of a shortest binary sequence that is not walkable.

4 4
0 0 1 1
1 2
1 3
2 3
3 4
4
6 7
0 0 1 1 0 1
1 2
3 1
1 4
2 3
4 2
3 4
5 6
infinity
1 0
0
1