Public Judge

pjudge

Límite de tiempo: 4 s Límite de memoria: 2048 MB Puntuación total: 7

#21905. 【PER #4】The Halting Problem

Estadísticas

You are given an undirected graph with $n$ vertices and $m$ edges. Each vertex $v$ has a number $a_v$ written on it, which is either $0$ or $1$.

A walk is a sequence of vertices $v_1 v_2 \dots v_k$ in the graph such that there is an edge between every two consecutive vertices in the sequence.

A binary sequence $s = s_1 s_2 \dots s_k$ is called walkable if and only if there exists a walk $v_1 v_2 \dots v_k$ in the graph such that the sequence of numbers on these vertices matches $s$, i.e., $a_{v_1} a_{v_2} \dots a_{v_k} = s$. In other words, a binary sequence is walkable if you can traverse the graph and record the numbers on the vertices in order to obtain that binary sequence.

An example is shown in the figure below.

In this example, any binary sequence of length at most 3 is walkable.

Your task is to find the length of the shortest binary sequence that is not walkable.

Input

The input contains:

  • The first line contains two integers $n$ and $m$ ($1 \leq n \leq 3 \cdot 10^5$, $0 \leq m \leq 3 \cdot 10^5$), representing the number of vertices and edges in the graph, respectively.
  • The second line contains $n$ integers $a_1, a_2, \dots, a_n$ (where each $a_v \in \{0, 1\}$), representing the number on each vertex $v$.
  • The next $m$ lines each contain two integers $u$ and $v$ ($1 \leq u, v \leq n$, $u \neq v$), representing an edge between vertex $u$ and vertex $v$. It is guaranteed that there is at most one edge between any two vertices.

Output

If all binary sequences are walkable, output "infinity".

Otherwise, output the length of the shortest binary sequence that is not walkable.

Examples

Input 1

4 4
0 0 1 1
1 2
1 3
2 3
3 4

Output 1

4

Input 2

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

Output 2

infinity

Subtasks

Subtask 1 (7 points)

No additional constraints.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.