#abc286g. G - Unique Walk

G - Unique Walk

Score : 600600 points

问题描述

你得到一个简单连通的无向图 GG,包含 NN 个顶点和 MM 条边。
GG 中的顶点编号为顶点 11、顶点 22\ldots 和顶点 NN,其边编号为边 11、边 22\ldots 和边 MM。其中边 ii 连接顶点 UiU_i 和顶点 ViV_i
同时,你还得到了图中边的一个子集:S={x1,x2,,xK}S=\{x_1,x_2,\ldots,x_K\}

判断在图 GG 上是否存在一条路径,使得对于所有 xSx \in S,路径恰好包含边 xx 一次。
该路径可以任意次数(包括零次)包含不属于集合 SS 的边。

什么是路径?在一个无向图 GG 上,路径是一个由 kk 个顶点(kk 是正整数)和 (k1)(k-1) 条边交替组成的序列,即 v1,e1,v2,,vk1,ek1,vkv_1,e_1,v_2,\ldots,v_{k-1},e_{k-1},v_k,其中边 eie_i 连接顶点 viv_i 和顶点 vi+1v_{i+1}。序列中可以包含相同边或顶点多次。若存在且仅存在一个 1ik11\leq i\leq k-1 满足 ei=xe_i=x,则称这条路径恰好包含边 xx 一次。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a simple connected undirected graph GG with NN vertices and MM edges.
The vertices of GG are numbered vertex 11, vertex 22, \ldots, and vertex NN, and its edges are numbered edge 11, edge 22, \ldots, and edge MM. Edge ii connects vertex UiU_i and vertex ViV_i.
You are also given a subset of the edges: S={x1,x2,,xK}S=\{x_1,x_2,\ldots,x_K\}.

Determine if there is a walk on GG that contains edge xx exactly once for all xSx \in S.
The walk may contain an edge not in SS any number of times (possibly zero).

What is a walk? A walk on an undirected graph GG is a sequence consisting of kk vertices (kk is a positive integer) and (k1)(k-1) edges occurring alternately, v1,e1,v2,,vk1,ek1,vkv_1,e_1,v_2,\ldots,v_{k-1},e_{k-1},v_k, such that edge eie_i connects vertex viv_i and vertex vi+1v_{i+1}. The sequence may contain the same edge or vertex multiple times. A walk is said to contain an edge xx exactly once if and only if there is exactly one 1ik11\leq i\leq k-1 such that ei=xe_i=x.

Constraints

  • 2N2×1052 \leq N \leq 2\times 10^5
  • $N-1 \leq M \leq \min(\frac{N(N-1)}{2},2\times 10^5)$
  • 1Ui<ViN1 \leq U_i<V_i\leq N
  • If iji\neq j, then (Ui,Vi)(Uj,Vj)(U_i,V_i)\neq (U_j,V_j) .
  • GG is connected.
  • 1KM1 \leq K \leq M
  • 1x1<x2<<xKM1 \leq x_1<x_2<\cdots<x_K \leq M
  • All values in the input are integers.

Input

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

NN MM

U1U_1 V1V_1

U2U_2 V2V_2

\vdots

UMU_M VMV_M

KK

x1x_1 x2x_2 \ldots xKx_K

Output

Print Yes if there is a walk satisfying the condition in the Problem Statement; print No otherwise.

Sample Input 1

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

Sample Output 1

Yes

The walk $(v_1,e_1,v_3,e_3,v_4,e_4,v_5,e_6,v_6,e_5,v_4,e_3,v_3,e_2,v_2)$ satisfies the condition, where viv_i denotes vertex ii and eie_i denotes edge ii.
In other words, the walk travels the vertices on GG in this order: 134564321\to 3\to 4\to 5\to 6\to 4\to 3\to 2.
This walk satisfies the condition because it contains edges 11, 22, 44, and 55 exactly once each.

Sample Input 2

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

Sample Output 2

No

There is no walk that contains edges 11, 22, and 33 exactly once each, so No should be printed.

update @ 2024/3/10 11:58:49