#P8287. 「DAOI R1」Flame

    ID: 9248 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>二分并查集O2优化广度优先搜索 BFSTarjan

「DAOI R1」Flame

Background

Tasting the apples in heaven is nothing special. I want to taste the apples in hell.

Problem Description

In the darkness there are black flames, and only those with sharp eyes can catch them.

With this tiny bit of humble light, walk deep into hell...

Welcome to the judgment ground of hell.

hhpq. \texttt{hhpq.} has forced D into the judgment ground of hell. D must escape before a Flame Prison is successfully formed in the City of Karma Fire, so he wants to know how many seconds are left.

In this City of Karma Fire, there are nn altars and mm bidirectional roads along which flames can spread.

It is known that there are kk altars whose flames (fire seeds) have already been lit. Starting from the first second, the fire will begin to spread from the lit altars to altars that can be reached and are not yet lit.

Once an altar is lit, it is activated instantly, and it will connect a holy wall of karma fire to every altar that has a road to it.

When there exists a closed shape formed by these holy walls of karma fire, the Flame Prison is formed successfully.

Simplified statement

You are given an undirected graph with nn vertices and mm edges. Each vertex has a label. Initially, kk vertices have label 1 (their indices are given), and the remaining vertices have label 0.

Each second, for every vertex labeled 1, all vertices connected to it by an edge will have their labels changed to 1.

Find the minimum number of seconds needed so that the vertices labeled 1 together with the edges between adjacent 1-labeled vertices can form a simple cycle.

In other words, find the minimum number of seconds after which there exists a set of vertices labeled 1 that forms a simple cycle.

Input Format

The first line contains three positive integers: n,m,kn, m, k.

The next mm lines each contain two positive integers: x,yx, y (altar xx and altar yy are connected by a karma-fire road).

The last line contains kk positive integers: the indices of the altars that have already been lit (have fire seeds).

Output Format

If D can escape, output how much time D has left.

Otherwise, if it is impossible to form a Flame Prison, output Poor D!.

3 3 1
1 2
2 3
3 1
1

1

5 4 2
1 2
2 3
3 4
2 5
1 5

Poor D!

15 15 2
2 1
2 3
2 9
5 9
4 5
5 7
6 7
7 8
7 11
11 10
10 9
10 14
14 15
11 12
12 13
4 15

3

Hint

Sample explanation

Sample 1 explanation

When time reaches the first second, the flame at altar 11 spreads to altars 22 and 33. At this point, a closed shape has already been formed, so the answer is 11.

Sample 2 explanation

It can be proved that no simple cycle can be formed in this case.

Constraints

Subtask nn\leq mm\leq kk\leq Points
00 10610^6 n1n-1 10410^4 55
11 2×1062\times10^6 11 1010
22 1010 4545 55
33 200200 500500 1010 1010
44 2×1032\times 10^3 5×1035\times 10^3 5050
55 5×1055\times10^5 6×1056\times10^5 500500 3030
66 10610^6 2×1062\times10^6 10410^4

Guarantees and notes

It is guaranteed that there are no multiple edges or self-loops in the graph.

It is guaranteed that the given graph is a connected undirected graph.

Help

The input size is large, so a fast input method is recommended.

Translated by ChatGPT 5