def check_possible_graph(n, m, k, original_edges, resulting_edges):
    original_graph = {i: set() for i in range(1, n + 1)}
    resulting_graph = {i: set() for i in range(1, n + 1)}

    # Creating adjacency list for original graph
    for edge in original_edges:
        a, b = edge
        original_graph[a].add(b)
        original_graph[b].add(a)

    # Creating adjacency list for resulting graph
    for edge in resulting_edges:
        a, b = edge
        resulting_graph[a].add(b)
        resulting_graph[b].add(a)

    # Function to check if graph can be obtained from the original graph
    def possible_graph(graph1, graph2):
        for i in range(1, n + 1):
            neighbors_graph1 = graph1[i]
            neighbors_graph2 = graph2[i]
            if neighbors_graph1 != neighbors_graph2:
                return False
        return True

    # Check if resulting graph is achievable from the original graph
    if not possible_graph(original_graph, resulting_graph):
        print("NO")
    else:
        print("YES")
        print("0")  # As we are not minimizing the steps
        # Here, you can add logic to output the steps needed, but for this case, it's not necessary.

# Reading input
n, m, k = map(int, input().split())
original_edges = [list(map(int, input().split())) for _ in range(m)]
resulting_edges = [list(map(int, input().split())) for _ in range(k)]

# Check possibility and print the result
check_possible_graph(n, m, k, original_edges, resulting_edges)
