#abc318g. G - Typical Path Problem
G - Typical Path Problem
Score : points
问题描述
你被给定一个简单的连通无向图 ,其中包含 个顶点和 条边。 图 中的顶点和边分别标记为顶点 、顶点 、、顶点 ,以及边 、边 、、边 ,其中第 条边 连接顶点 和顶点 。
另外,你还被赋予了图 上互不相同的三个顶点 、 和 。你需要确定是否存在一条通过顶点 连接顶点 和顶点 的简单路径。
什么是简单连通无向图?若一个图 是无向且既是简单图又是连通图,则称其为简单连通无向图。
若图 的边没有方向,则称其为无向图。
若图 不包含自环和平行边,则称其为简单图。
若在图 中可以通过边从所有顶点的一个到达另一个,则称其为连通图。什么是通过顶点 的简单路径?对于图 上的顶点 和 ,连接 和 的简单路径是一个由不同顶点组成的序列 ,满足 、,并且对于每个整数 满足 ,在图 上存在一条连接顶点 和 的边。
如果对于某个 满足 ,则称该简单路径 是通过顶点 的路径。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given a simple connected undirected graph with vertices and edges.
The vertices and edges of are numbered as vertex , vertex , , vertex , and edge , edge , , edge , respectively, and edge connects vertices and .
You are also given distinct vertices on . Determine if there is a simple path connecting vertices and via vertex .
What is a simple connected undirected graph? A graph is said to be a simple connected undirected graph when is an undirected graph that is simple and connected.
A graph is said to be an undirected graph when the edges of have no direction.
A graph is simple when does not contain self-loops or multi-edges.
A graph is connected when one can travel between all vertices of via edges. What is a simple path via vertex ? For vertices and on a graph , a simple path connecting and is a sequence of distinct vertices such that , , and for every integer satisfying , there is an edge on connecting vertices and .
A simple path is said to be via vertex when there is an satisfying .
Constraints
- $N-1\leq M\leq\min\left(\frac{N(N-1)}{2},2\times 10^5\right)$
- , , and are all distinct.
- The pairs are all distinct.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
If there is a simple path that satisfies the condition in the statement, print Yes
; otherwise, print No
.
Sample Input 1
6 7
1 3 2
1 2
1 5
2 3
2 5
2 6
3 4
4 5
Sample Output 1
Yes
One simple path connecting vertices and via vertex is .
Thus, print Yes
.
Sample Input 2
6 6
1 3 2
1 2
2 3
2 5
2 6
3 4
4 5
Sample Output 2
No
No simple path satisfies the condition. Thus, print No
.
Sample Input 3
3 2
1 3 2
1 2
2 3
Sample Output 3
No
update @ 2024/3/10 09:05:42