#P8287. Hell's Judgment

    ID: 21466 Type: Default 1000ms 256MiB

Hell's Judgment

Hell's Judgment

In the dark, there is a flame that only those with keen eyes can detect. Using this meager glimmer, you traverse the depths of hell...

Welcome to the Judgment Grounds of Hell.

The entity hhpq. has ushered D into this ground, and D must escape before a "Hellfire Prison" is built in the City of Hellfire. To do so, he needs to know how many seconds remain.

The City of Hellfire is modeled as an undirected graph with n altars (nodes) and m bidirectional roads (edges). Initially, k altars are ignited (marked as 1), while the others are 0. Starting from the first second, for every altar that is ignited (has a mark of 1), all altars directly connected to it by a road become ignited as well.

Once an altar is ignited, it is activated immediately, and the connecting roads become a part of the "Holy Wall of Hellfire". When these walls form a closed simple cycle (a simple cycle is a cycle that does not repeat nodes except the starting and ending node and has at least 3 nodes) in the subgraph induced by altars marked with 1, the Hellfire Prison is successfully generated.

Your task is to determine the minimum number of seconds required such that the subgraph induced by the altars marked as 1 (and the roads between them) contains a simple cycle.


Simplified Problem Statement:

You are given an undirected graph with n nodes and m edges. Initially, k nodes are marked as 1 (their indices are provided) and the remaining nodes are marked as 0. Every second, for each node with mark 1, all of its adjacent nodes become marked 1. Determine the minimum number of seconds needed until the nodes marked as 1 and the edges between them form a simple cycle. If it is impossible, output -1.

inputFormat

The first line contains three integers n, m and k, representing the number of nodes, edges, and initially activated nodes respectively.

The second line contains k distinct integers indicating the indices (1-indexed) of the initially activated nodes.

Each of the next m lines contains two integers u and v, indicating an undirected edge between nodes u and v.

outputFormat

Output a single integer: the minimum number of seconds required such that the subgraph induced by nodes marked 1 contains a simple cycle. If no such cycle ever forms, output -1.

sample

3 3 1
1
1 2
2 3
3 1
1