Sopsug

아직 제출이 없습니다시간 제한5초메모리 제한1024 MB

문제

Grushög is an unfinished residential area in the outskirts of Lund. Right now, all necessary infrastructure is being constructed, including the most important thing of all: garbage disposal. Like in many areas of Sweden, a sopsug (automated vacuum collection system) will be used to collect garbage. The idea is to transport garbage underground through tubes using air pressure.

There are NN buildings in Grushög, numbered from 00 to N1N-1. Your task is to connect some pairs of buildings with tubes. If you build a tube from building uu to some other building vv, uu will send all of its garbage to vv (but not in the other direction). Your goal is to create a network of N1N-1 tubes such that all garbage ends up in one building. In other words, you want the network to form a rooted tree, where the edges are directed toward the root.

However, MM tubes have already been constructed between buildings. These must be used in your network. These tubes are directed, so they can only be used in one direction.

Furthermore, there are KK pairs of buildings between which it is impossible to build a tube. These pairs are ordered, so if it is impossible to build a tube from uu to vv, it may still be possible to build one from vv to uu.

입력

The first line of input contains the three integers, NN, MM, and KK.

The following MM lines each contain two distinct integers a_i,b_ia\_i, b\_i, meaning that there is already a tube from a_ia\_i to b_ib\_i.

The following KK lines each contain two distinct integers c_i,d_ic\_i, d\_i, meaning that it is impossible to build a tube from c_ic\_i to d_id\_i.

All of the M+KM+K ordered pairs in the input will be distinct. Note that (u,v)(u,v) and (v,u)(v,u) are regarded as different pairs.

출력

If there is no solution, print NO.

Otherwise, print N1N-1 lines, each containing two integers u_iu\_i, v_iv\_i, meaning that there should be a tube directed from u_iu\_i to v_iv\_i. You may print the tubes in any order. If there are multiple solutions, you may print any of them. Remember that all the MM already existing tubes must be included in your solution.

제한

  • 2N300,0002 \leq N \leq 300\\,000.
  • 0M300,0000 \leq M \leq 300\\,000.
  • 0K300,0000 \leq K \leq 300\\,000.
  • 0a_i,b_iN10 \leq a\_i, b\_i \leq N-1 for i=0,1,,M1i = 0, 1, \ldots, M-1.
  • 0c_i,d_iN10 \leq c\_i, d\_i \leq N-1 for i=0,1,,K1i = 0, 1, \ldots, K-1.

힌트

The following figures show the first and second sample test cases. The blue edges mark tubes which are already constructed, and the dashed red edges mark tubes which are impossible to build.

The figure to the left shows the first sample with the solution from the sample output, showing tubes with black edges (in addition to the already constructed tube from 44 to 11 which is blue). In this network, all garbage will be collected in building 00. This is not the only solution; for example, the tube from 11 to 33 can be replaced by a tube from 00 to 11 and it is still a valid solution.

For the second sample input, we can see in the right figure that it is impossible to construct a solution because of the cycle (2,3,4)(2, 3, 4).