atcoder#ARC150C. [ARC150C] Path and Subsequence
[ARC150C] Path and Subsequence
Score : points
Problem Statement
We have a connected undirected graph with vertices and edges. The vertices are numbered to . The -th edge connects vertices and .
Additionally, we are given an integer sequence of length , , and an integer sequence of length , .
Determine whether , , and satisfy the following condition.
- For every simple path from vertex to in , , is a (not necessarily contiguous) subsequence of .
Constraints
- if .
- All values in the input are integers.
- The given graph is connected.
Input
The input is given from Standard Input in the following format:
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 to vertex : and . The corresponding to these paths are and . Both of them have 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 from vertex to vertex , the is , which does not have 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