Logo
(追記) (追記ここまで)

32890번 - Binary Search 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 (추가 시간 없음) 1024 MB39262668.421%

문제

You are given an undirected graph with $n$ vertices and $m$ edges. Each vertex $v$ has a number $a_v$ written on it. This number is either 0ドル$ or 1ドル$. A walk is a sequence $v_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 = s_1s_2 \dots s_k$$ walkable if there is a walk $v_1v_2 \dots v_k$ in the graph that satisfies $a_{v_1} a_{v_2} \dots a_{v_k} = s$.

In other words, a binary sequence is walkable if it is possible to obtain $s$ 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 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 $n$ and $m$ (1ドル \leq n \leq 3 \cdot 10^5,ドル 0ドル \leq m \leq 3 \cdot 10^5$), the number of vertices and the number of edges.
  • One line with $n$ integers $a_1,\dots, a_n$ ($a_v \in \{0, 1\}$ for each $v$), where $a_v$ is the number written on vertex $v$.
  • $m$ lines, each with two integers $u$ and $v$ (1ドル \leq u,v \leq n,ドル $u \neq v$), denoting that the vertices $u$ and $v$ 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.

제한

예제 입력 1

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

예제 출력 1

4

예제 입력 2

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

예제 출력 2

infinity

예제 입력 3

1 0
0

예제 출력 3

1

힌트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > NWERC 2024 B번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /