#ARC150C. [ARC150C] Path and Subsequence

[ARC150C] Path and Subsequence

Score : 500500 points

Problem Statement

We have a connected undirected graph GG with NN vertices and MM edges. The vertices are numbered 11 to NN. The ii-th edge connects vertices UiU_i and ViV_i.

Additionally, we are given an integer sequence of length NN, A=(A1, A2,, AN)A=(A_1,\ A_2, \dots,\ A_N), and an integer sequence of length KK, B=(B1, B2, , BK)B=(B_1,\ B_2,\ \dots,\ B_K).

Determine whether GG, AA, and BB satisfy the following condition.

  • For every simple path from vertex 11 to NN in GG, v=(v1, v2,, vk) (v1=1, vk=N)v=(v_1,\ v_2, \dots,\ v_k)\ (v_1=1,\ v_k=N), BB is a (not necessarily contiguous) subsequence of (Av1, Av2, , Avk)(A_{v_1},\ A_{v_2},\ \dots,\ A_{v_k}).

Constraints

  • 2N1052 \leq N \leq 10^5
  • 1KN1 \leq K \leq N
  • N1M2×105N-1 \leq M \leq 2 \times 10^5
  • 1Ui<ViN1 \leq U_i < V_i \leq N
  • (Ui, Vi)(Uj, Vj)(U_i,\ V_i) \neq (U_j,\ V_j) if iji \neq j.
  • 1Ai, BiN1 \leq A_i,\ B_i \leq N
  • All values in the input are integers.
  • The given graph GG is connected.

Input

The input is given from Standard Input in the following format:

NN MM KK

U1U_1 V1V_1

U2U_2 V2V_2

\vdots

UMU_M VMV_M

A1A_1 A2A_2 \dots ANA_N

B1B_1 B2B_2 \dots BKB_K

Output

If the condition is satisfied, print Yes; otherwise, print No.

6 6 3
1 2
1 3
2 4
3 5
4 6
5 6
1 2 4 5 2 6
1 2 6
Yes

There are two simple paths from vertex 11 to vertex 66: (1, 2, 4, 6)(1,\ 2,\ 4,\ 6) and (1, 3, 5, 6)(1,\ 3,\ 5,\ 6). The (Av1, Av2, , Avk)(A_{v_1},\ A_{v_2},\ \dots,\ A_{v_k}) corresponding to these paths are (1, 2, 5, 6)(1,\ 2,\ 5,\ 6) and (1, 4, 2, 6)(1,\ 4,\ 2,\ 6). Both of them have B=(1, 2, 6)B=(1,\ 2,\ 6) as a subsequence, so the answer is Yes.

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

For a simple path (1, 2, 5)(1,\ 2,\ 5) from vertex 11 to vertex 55, the (Av1, Av2, , Avk)(A_{v_1},\ A_{v_2},\ \dots,\ A_{v_k}) is (1, 2, 2)(1,\ 2,\ 2), which does not have B=(1, 3, 2)B=(1,\ 3,\ 2) as a subsequence.

10 20 3
5 6
5 10
5 7
3 5
3 7
2 6
3 8
4 5
5 8
7 10
1 6
1 9
4 6
1 2
1 4
6 7
4 8
2 5
3 10
6 9
2 5 8 5 1 5 1 1 5 10
2 5 1
Yes