#DSU0000064. Truy vấn đường đi duy nhất trên đồ thị một chu trình (Well-defined Path Queries on a Namori)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Truy vấn đường đi duy nhất trên đồ thị một chu trình (Well-defined Path Queries on a Namori)
Well-defined Path Queries on a Namori
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a connected undirected graph with vertices and exactly edges. There are no self-loops or duplicate edges. Such a graph contains exactly one simple cycle.
A simple path from to is a sequence of vertices starting at and ending at , with consecutive vertices connected by edges and no vertex visited more than once. Because the graph contains a cycle, two vertices may have more than one distinct simple path between them.
You are given queries, each specifying two distinct vertices . For each query, determine whether there is exactly one simple path between them. Queries do not modify the graph.
Input
Read , then exactly distinct edges with . Read , then query pairs with .
Output
Print Yes for a unique simple path, otherwise No, one answer per line.
Subtasks
- Subtask 1 (20 points): , ; , ; the graph is simple, connected, and has exactly distinct edges.
- Subtask 2 (30 points): , ; , ; the graph is simple, connected, and has exactly distinct edges.
- Subtask 3 (50 points): , ; , ; the graph is simple, connected, and has exactly distinct edges.
Examples
Input
4
1 2
2 3
1 3
3 4
3
1 2
3 4
1 4
Output
No
Yes
No
Explanation
Vertices are on the cycle, and vertex lies in the tree attached to . Only pair has a unique simple path.