Twinning Totem

시간 제한2초메모리 제한2048 MB

요약
연결된 그래프가 주어질 때, 각 질의 루트 u에 대해 u에서 v로 가는 두 신장 트리 경로가 양 끝점만 공유하도록 하는 두 신장 트리가 존재하는지 판정하고, 존재하면 출력한다.
난이도

어려움10점 중 8점

유형
그래프, DFS, 트리, 그리디
정답자
아직 제출이 없습니다

문제

"Ori, this is a Map Stone, one of the many ancient markers created to chart the forest of Nibel as it grew."

The Map Stone that Ori meets today is different from the others. The totem has two sides, and each side has nn hollows with mm scratches. Each scratch connects two hollows, and the hollows and the scratches on the two sides are the same. Each hollow can pass through the stone so that, if we put something on one side, we could also see it on the other side. However, the scratches are the same but cannot pass through, so we can put different things on two sides for each scratch.

Ori puts one Life Cell into hollow uu and n−1n - 1 Energy Cells into the other n−1n - 1 hollows. Now, on each side, Ori needs to select n−1n - 1 scratches and inject light to them to form a spanning tree rooted in uu. The two resulting trees should have the following property: for each Energy Cell, if it flows its energy to the Life Cell along light scratches on one side, and then flows back along the light scratches on the other side, no other Energy Cell will be passed twice.

Could Ori find two trees with the required properties?

입력

The first line contains two integers nn and mm (3≤n≤1053 \le n \le 10^5, n−1≤m≤min⁡(2⋅105n - 1 \le m \le \min(2 \cdot 10^5, n(n−1)2)\frac{n(n - 1)}{2})) denoting the number of hollows and the number of scratches of the totem GG, respectively.

For the next mm lines, the ii-th line contains two integers x_ix\_i and y_iy\_i (1≤x_i,y_i≤n1 \le x\_i, y\_i \le n) denoting a scratch connecting hollow x_ix\_i and hollow y_iy\_i.

The next line contains an integer TT (1≤T≤1051 \le T \le 10^5) denoting the number of Ori's attempts.

For the next TT lines, the ii-th line contains an integer u_iu\_i (1≤u_i≤n1 \le u\_i \le n) denoting the hollow where Ori puts the Life Cell in the ii-th attempt.

It is guaranteed that GG is a connected graph without self-loops or multiple edges, and that n⋅T≤105n \cdot T \le 10^5.

출력

For each attempt of Ori, if no solution exists, output "No" (without quotes) on the first line.

Otherwise, output "Yes" (without quotes) on the first line. Then, output 2(n−1)2(n - 1) lines to describe the two spanning trees.

For the first n−1n - 1 of these lines, the ii-th line must contain two integers x_ix\_i and y_iy\_i (1≤x_i,y_i≤n1 \le x\_i, y\_i \le n) separated by a space, denoting a selected scratch connecting x_ix\_i and y_iy\_i. The n−1n - 1 scratches must form the first spanning tree of GG.

The next n−1n - 1 lines must describe the second spanning tree of GG in the same format.

Your answer will be accepted only when the two trees you output are valid spanning trees of GG and meet the requirements in the problem description: for any v∈Vv \in V such that v≠uv \ne u, the two simple paths from uu to vv in the two trees have no common nodes except their endpoints uu and vv.

힌트

For the first example:

  • For hollow 22, the paths in the two trees are P_1=2,1P\_1 = \\{2, 1\\} and P_2=2,3,4,1P\_2 = \\{2, 3, 4, 1\\}.
  • For hollow 33, the paths in the two trees are P_1=3,2,1P\_1 = \\{3, 2, 1\\} and P_2=3,4,1P\_2 = \\{3, 4, 1\\}.
  • For hollow 44, the paths in the two trees are P_1=4,3,2,1P\_1 = \\{4, 3, 2, 1\\} and P_2=4,1P\_2 = \\{4, 1\\}.

예제2

  1. 예제 1

    입력
    4 6
    1 2
    1 3
    1 4
    2 3
    2 4
    3 4
    1
    1
    
    예상 출력
    Yes
    1 2
    2 3
    3 4
    3 2
    4 3
    1 4
    
  2. 예제 2

    입력
    4 4
    1 3
    2 3
    2 4
    3 4
    4
    1
    2
    3
    4
    
    예상 출력
    No
    No
    Yes
    3 1
    4 2
    3 4
    3 1
    3 2
    2 4
    No