포럼
문제 ICPC00221

B. Binary Search

설명

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 .

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
출력
4
예제 2
입력
6 7
0 0 1 1 0 1
1 2
3 1
1 4
2 3
4 2
3 4
5 6
출력
infinity
예제 3
입력
1 0
0
출력
1
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC NWERC 2024

평가 및 의견

B. Binary Search

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

B. Binary Search

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8