{"problem":{"name":"Path and Subsequence","description":{"content":"We have a connected undirected graph $G$ with $N$ vertices and $M$ edges. The vertices are numbered $1$ to $N$. The $i$\\-th edge connects vertices $U_i$ and $V_i$. Additionally, we are given an intege","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"arc150_c"},"statements":[{"statement_type":"Markdown","content":"We have a connected undirected graph $G$ with $N$ vertices and $M$ edges. The vertices are numbered $1$ to $N$. The $i$\\-th edge connects vertices $U_i$ and $V_i$.\nAdditionally, we are given an integer sequence of length $N$, $A=(A_1,\\ A_2, \\dots,\\ A_N)$, and an integer sequence of length $K$, $B=(B_1,\\ B_2,\\ \\dots,\\ B_K)$.\nDetermine whether $G$, $A$, and $B$ satisfy the following condition.\n\n*   For every simple path from vertex $1$ to $N$ in $G$, $v=(v_1,\\ v_2, \\dots,\\ v_k)\\ (v_1=1,\\ v_k=N)$, $B$ is a (not necessarily contiguous) subsequence of $(A_{v_1},\\ A_{v_2},\\ \\dots,\\ A_{v_k})$.\n\n## Constraints\n\n*   $2 \\leq N \\leq 10^5$\n*   $1 \\leq K \\leq N$\n*   $N-1 \\leq M \\leq 2 \\times 10^5$\n*   $1 \\leq U_i < V_i \\leq N$\n*   $(U_i,\\ V_i) \\neq (U_j,\\ V_j)$ if $i \\neq j$.\n*   $1 \\leq A_i,\\ B_i \\leq N$\n*   All values in the input are integers.\n*   The given graph $G$ is connected.\n\n## Input\n\nThe input is given from Standard Input in the following format:\n\n$N$ $M$ $K$\n$U_1$ $V_1$\n$U_2$ $V_2$\n$\\vdots$\n$U_M$ $V_M$\n$A_1$ $A_2$ $\\dots$ $A_N$\n$B_1$ $B_2$ $\\dots$ $B_K$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"arc150_c","tags":[],"sample_group":[["6 6 3\n1 2\n1 3\n2 4\n3 5\n4 6\n5 6\n1 2 4 5 2 6\n1 2 6","Yes\n\nThere are two simple paths from vertex $1$ to vertex $6$: $(1,\\ 2,\\ 4,\\ 6)$ and $(1,\\ 3,\\ 5,\\ 6)$. The $(A_{v_1},\\ A_{v_2},\\ \\dots,\\ A_{v_k})$ corresponding to these paths are $(1,\\ 2,\\ 5,\\ 6)$ and $(1,\\ 4,\\ 2,\\ 6)$. Both of them have $B=(1,\\ 2,\\ 6)$ as a subsequence, so the answer is `Yes`."],["5 5 3\n1 2\n2 3\n3 4\n4 5\n2 5\n1 2 3 5 2\n1 3 2","No\n\nFor a simple path $(1,\\ 2,\\ 5)$ from vertex $1$ to vertex $5$, the $(A_{v_1},\\ A_{v_2},\\ \\dots,\\ A_{v_k})$ is $(1,\\ 2,\\ 2)$, which does not have $B=(1,\\ 3,\\ 2)$ as a subsequence."],["10 20 3\n5 6\n5 10\n5 7\n3 5\n3 7\n2 6\n3 8\n4 5\n5 8\n7 10\n1 6\n1 9\n4 6\n1 2\n1 4\n6 7\n4 8\n2 5\n3 10\n6 9\n2 5 8 5 1 5 1 1 5 10\n2 5 1","Yes"]],"created_at":"2026-03-03 11:01:14"}}