#P12939. [NERC 2019] Foolprüf Security

    ID: 12735 Type: RemoteJudge 3000ms 512MiB Tried: 0 Accepted: 0 Difficulty: 6 Uploaded By: Tags>2019Special JudgeICPCPrüfer 序列NERC/NEERC

[NERC 2019] Foolprüf Security

题目描述

Alice and Bob obtained a map of the secret underground facility. The facility consists of nn security units\emph{security units} and mm chemical labs\emph{chemical labs}, connected by bidirectional tunnels. The map of this facility forms a tree\emph{tree}: there are exactly n+m1n + m - 1 tunnels, and there are no cycles. Vertices corresponding to security units have numbers from 11 to nn, chemical labs have numbers from n+1n+1 to n+mn+m. Each tunnel connects a security unit to a chemical lab; there are no tunnels between two security units or two chemical labs.

In case Alice or Bob gets captured, they decided to split the map into two pieces. To do that, they calculated the Pru¨fer code\emph{Prüfer code} of the tree. Alice then saved some of the numbers between 11 and nn to her data storage in the same order as they go in the original code, and Bob saved some of the numbers from n+1n+1 to n+mn+m to his storage in the same way.

A Prüfer code of a tree on kk vertices is a sequence of k2k - 2 integers from 11 to kk, constructed as follows. Find the leaf (a vertex with degree one) with the smallest label, remove it from the tree, then print the label of its only neighbor. Repeat this k3k - 3 more times, until only one edge remains. The printed sequence of k2k - 2 vertex labels is the Prüfer code.

Alice and Bob safely returned and they are ready to combine their data to restore the original map. They could make a mistake during the backup, meaning no such map exists. Alice and Bob need your help to restore any possible map of the facility consistent with the collected data, so that both Alice's and Bob's parts are subsequences of the Prüfer code of the map.

输入格式

The first line of the input contains four integers nn, mm, kak_a, and kbk_b (2n,m1052 \le n, m \le 10^5; 1ka,kb1 \le k_a, k_b; ka+kbn+m2k_a + k_b \le n + m - 2). The second line contains kak_a integers a1,a2,,akaa_1, a_2, \ldots, a_{k_a} (1ain1 \le a_i \le n) --- Alice's part of the map. The third line contains kbk_b integers b1,b2,,bkbb_1, b_2, \ldots, b_{k_b} (n+1bin+mn + 1 \le b_i \le n + m) --- Bob's part of the map.

输出格式

If there's no such map, print No\tt{No}.

Otherwise, print Yes\tt{Yes} on the first line, followed by n+m1n + m - 1 lines describing the possible facility map. Each line should contain two integers uiu_i and viv_i --- the security unit and the chemical lab connected by the ii-th tunnel of the facility.

4 5 4 2
1 3 3 4
7 8
Yes
1 5
1 6
2 7
6 3
3 7
9 4
3 8
4 8
4 3 3 1
3 2 2
6
No

提示

The Prüfer code of the tree in the first example is $(\underline{7}, \mathbf{1}, 6, \mathbf{3}, \mathbf{3}, \underline{8}, \mathbf{4})$.