Find the Vertex

연결된 무방향 그래프와 알 수 없는 시작 정점에서 각 정점까지의 최단 거리를 3으로 나눈 나머지가 주어질 때, 시작 정점이 될 수 있는 정점을 아무거나 하나 찾는다.

어려움9그래프BFS수학정수론아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

You are given a connected undirected graph with n vertices and m edges. The vertices are numbered from 1 to n. The vertex number s is the initial vertex. You don’t know the number s, but you know all distances from vertex s to every other vertex including itself, taken modulo 3. You have to find the number s.

The distance between two vertices is the length of the shortest path between them. The length of a path is the number of edges in it.

입력

The first line contains two integers n and m (1 ≤ n, m ≤ 500 000), the number of vertices and the number of edges.

The second line contains n integers d1, d2, . . . , dn (0 ≤ di ≤ 2). Here, di is the distance between vertices s and i, taken modulo 3.

The next m lines describe the edges. The i-th of these lines describes i-th edge and contains two integers u and v (1 ≤ u, v ≤ n), the indices of vertices connected by this edge.

It is guaranteed that there are no self-loops and no multiple edges in the graph. Also, it is guaranteed that the graph is connected.

출력

Print the number s: the index of the initial vertex. If there are multiple answers, print any one of them.

힌트

In the first sample, the array of lengths of paths between vertex 2 and all vertices is [1, 0, 1, 1, 2]. It is equal to the given array d.

In the second sample, the array of lengths of paths from vertex 1 is [0, 1, 2, 3, 2, 1]. If we take each element modulo 3, we will get the array d.