This page is still under construction.

Parts of this page are still being built. What you see may change.

One-Way Roads

Interview

Time limit2sMemory limit64 MB

Summary
Decide whether the undirected streets of a graph can all be oriented so that each required ordered pair stays reachable from the first to the second.
Level

Hard8 of 10

Topics
Graph, DFS, Union-find, Greedy
Solved
No attempts yet

Problem

The capital of Byteland suffers from severe traffic congestion, so the city authorities have decided to make every street one-way. If the directions are chosen carelessly, some junctions may become unreachable from others.

The transport department has prepared a list of pairs of junctions that must stay connected after the change. For each pair (p,q)(p, q), once every street has been made one-way it must still be possible to travel from junction pp to junction qq.

Write a program that decides whether it is possible to assign a direction to every street so that all of these requirements are satisfied.

Input

The first line contains three integers nn, mm, and kk (1≤n≤50 0001 \le n \le 50\,000, 0≤m,k≤200 0000 \le m, k \le 200\,000): the number of junctions, the number of streets, and the number of requirements. Junctions are numbered from 11 to nn.

Each of the next mm lines contains two integers aia_i and bib_i (1≤ai,bi≤n1 \le a_i, b_i \le n, ai≠bia_i \ne b_i), describing a two-way street between junctions aia_i and bib_i. There is at most one street between any pair of junctions.

Each of the next kk lines contains two integers pip_i and qiq_i (1≤pi,qi≤n1 \le p_i, q_i \le n, pi≠qip_i \ne q_i), meaning that after every street is made one-way it must be possible to travel from pip_i to qiq_i.

Output

Print YES if every street can be made one-way so that all requirements are satisfied, and NO otherwise.

Examples2

  1. Example 1

    Input
    4 4 3
    1 2
    2 3
    3 1
    2 4
    1 3
    3 1
    1 4
    
    Expected output
    YES
    
  2. Example 2

    Input
    4 3 2
    1 2
    1 3
    1 4
    3 4
    2 3
    
    Expected output
    NO