402193: GYM100694 C Modern Art

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Modern Arttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Sergey is a modern artist who uses 3D printer in his works. He has just come up with the idea of his next work. He is going to print n colored bars and place them horizontally one over another (the bars can be considered as horizontal segments on the plane, which have positive lengths and belong to pairwise distinct lines parallel to X-axis), but he also wants to satisfy some conditions (he is an artist, after all). There are two types of conditions: precendence (type A) and intersection (type B).

If there is a precendence condition between two bars i and j, the bar i must be placed strictly to the left of the bar j (that is, X-coordinate of any point of bar i must be strictly less than X-coordinate of any point of bar j).

Intersection condition between bars i and j means that both bars must have at least one point which is not an end such that the X-coordinates of these points are equal.

If there are no conditions between some two bars, they can be placed in any order relatively to each other.

Help Sergey to find perfect X-coordinates for his bars or say that it's impossible. If his work is successful he might even share his earnings with you!

Input

The first line contains three space-separated integers n, a and b (1 ≤ n ≤ 105, 0 ≤ a, b ≤ 105) — the number of bars and the numbers of conditions of type A and type B.

Each of the next a lines contains two space-separated integers fa[i] and sa[i] (1 ≤ fa[i], sa[i] ≤ n, fa[i] ≠ sa[i]) — the indices of bars for which the condition of type A must be satisfied.

Each of the next b lines contains two space-separated integers fb[i] and sb[i] (1 ≤ fb[i], sb[i] ≤ n, fb[i] ≠ sb[i]) — the indices of bars for which the condition of type B must be satisfied.

Output

If the required arrangement of bars doesn't exist, write «NO» (without quotes).

Otherwise in the first line write «YES» (without quotes). Next, write n lines, the i-th of which should contain two integers li and ri (0 ≤ li < ri ≤ 109) — the X-coordinates of the left and right ends of the i-th bar.

ExamplesInput
4 2 1
1 2
2 3
3 4
Output
YES
0 1
2 3
4 6
5 7
Input
3 2 0
1 2
2 1
Output
NO

加入题单

算法标签: