102866: [AtCoder]ABC286 G - Unique Walk

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $600$ points

Problem Statement

You are given a simple connected undirected graph $G$ with $N$ vertices and $M$ edges.
The vertices of $G$ are numbered vertex $1$, vertex $2$, $\ldots$, and vertex $N$, and its edges are numbered edge $1$, edge $2$, $\ldots$, and edge $M$. Edge $i$ connects vertex $U_i$ and vertex $V_i$.
You are also given a subset of the edges: $S=\{x_1,x_2,\ldots,x_K\}$.

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

What is a walk? A walk on an undirected graph $G$ is a sequence consisting of $k$ vertices ($k$ is a positive integer) and $(k-1)$ edges occurring alternately, $v_1,e_1,v_2,\ldots,v_{k-1},e_{k-1},v_k$, such that edge $e_i$ connects vertex $v_i$ and vertex $v_{i+1}$. The sequence may contain the same edge or vertex multiple times. A walk is said to contain an edge $x$ exactly once if and only if there is exactly one $1\leq i\leq k-1$ such that $e_i=x$.

Constraints

  • $2 \leq N \leq 2\times 10^5$
  • $N-1 \leq M \leq \min(\frac{N(N-1)}{2},2\times 10^5)$
  • $1 \leq U_i<V_i\leq N$
  • If $i\neq j$, then $(U_i,V_i)\neq (U_j,V_j)$ .
  • $G$ is connected.
  • $1 \leq K \leq M$
  • $1 \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:

$N$ $M$
$U_1$ $V_1$
$U_2$ $V_2$
$\vdots$
$U_M$ $V_M$
$K$
$x_1$ $x_2$ $\ldots$ $x_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 $v_i$ denotes vertex $i$ and $e_i$ denotes edge $i$.
In other words, the walk travels the vertices on $G$ in this order: $1\to 3\to 4\to 5\to 6\to 4\to 3\to 2$.
This walk satisfies the condition because it contains edges $1$, $2$, $4$, and $5$ 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 $1$, $2$, and $3$ exactly once each, so No should be printed.

Input

题意翻译

有一张 $n$ 个点 $m$ 条边的无向连通图,已知 $k$ 条边为关键边,需要经过每条关键边恰好一次,非关键边无限制,判断能否满足条件。

Output

得分:$600$分

问题描述

你被给定一个简单连接的无向图$G$,它有$N$个顶点和$M$条边。
$G$的顶点编号为顶点$1$,顶点$2$,$\ldots$,顶点$N$,它的边编号为边$1$,边$2$,$\ldots$,边$M$。 边$i$连接顶点$U_i$和顶点$V_i$。
你还会得到边的一个子集:$S=\{x_1,x_2,\ldots,x_K\}$。

确定是否存在一条在$G$上的路径,该路径恰好包含子集$S$中的每一条边一次。
路径可以包含不在$S$中的边任意多次(可能为零次)。

什么是路径? 在无向图$G$上,路径是一个由$k$个顶点($k$是一个正整数)和$(k-1)$条边交替组成的序列,$v_1,e_1,v_2,\ldots,v_{k-1},e_{k-1},v_k$,满足 边$e_i$连接顶点$v_i$和顶点$v_{i+1}$。序列可以包含多次相同的边或顶点。 一条路径被认为恰好包含一条边$x$一次,当且仅当存在恰好一个$1\leq i\leq k-1$,使得$e_i=x$。

约束

  • $2 \leq N \leq 2\times 10^5$
  • $N-1 \leq M \leq \min(\frac{N(N-1)}{2},2\times 10^5)$
  • $1 \leq U_i<V_i\leq N$
  • 如果$i\neq j$,那么$(U_i,V_i)\neq (U_j,V_j)$ .
  • $G$是连通的。
  • $1 \leq K \leq M$
  • $1 \leq x_1<x_2<\cdots<x_K \leq M$
  • 输入中的所有值都是整数。

输入

输入以标准输入的以下格式给出:

$N$ $M$
$U_1$ $V_1$
$U_2$ $V_2$
$\vdots$
$U_M$ $V_M$
$K$
$x_1$ $x_2$ $\ldots$ $x_K$

输出

如果存在满足条件的路径,则打印Yes;否则打印No


样例输入 1

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

样例输出 1

Yes

路径$(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)$满足条件,其中$v_i$表示顶点$i$,$e_i$表示边$i$。
换句话说,路径按照以下顺序遍历$G$上的顶点:$1\to 3\to 4\to 5\to 6\to 4\to 3\to 2$。
路径满足条件,因为它恰好包含边$1$,$2$,$4$和$5$各一次。


样例输入 2

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

样例输出 2

No

不存在一条路径恰好包含边$1$,$2$和$3$各一次,所以应该打印No

加入题单

上一题 下一题 算法标签: