#!/usr/bin/python3

from sys import argv, stdin, stderr, exit

MAXQ = 500000

assert len(argv)==4, f'correct usage: python3 {argv[0]} input our_output contestants_output'

###############################################################################################

class DisjointSet:
    def __init__(self, N):
        self.degree = [ 0 for n in range(N) ]
        self.color = [ n for n in range(N) ]
        self.components = [ [n] for n in range(N) ]

    def union(self, x, y):
        cx, cy = self.color[x], self.color[y]
        if cx == cy: return
        nx, ny = len(self.components[cx]), len(self.components[cy])
        if nx < ny: cx, cy = cy, cx
        for ex in self.components[cy]:
            self.components[cx].append(ex)
            self.color[ex] = cx
        self.components[cy] = []

def process_their_output(N, K, P, DS, stupne, is_solvable):
    try:
        their_output = open(argv[3],'r').readlines()
    except:
        assert False, 'Vystup programu obsahuje nepovolene znaky (neni to ASCII text).'

    their_output = [ row.strip() for row in their_output ]

    assert len(their_output) > 0, 'Program mel prazdny vystup.'
    try:
        Q = int( their_output[0] )
    except:
        assert False, 'Prvni radek vystupu ma obsahovat jedno cislo.'

    assert -1 <= Q <= MAXQ, 'Cislo q ma byt bud -1 alebo nejvyse 500 000.'
    if Q == -1:
        if is_solvable:
            assert False, 'Existuje reseni, ale program tvrdi, ze ne.'
        else:
            return # all OK

    assert len(their_output) == Q+1, 'Vystup musi mit presne q+1 radku.'
    for line in their_output[1:]:
        try:
            x, y = [ int(_) for _ in line.split() ]
        except:
            assert False, 'Kazdy popis potrubi ma byt tvoreny dvema cisly.'
        assert 0 <= x < N, 'Neplatne cislo kancelare.'
        assert 0 <= y < N, 'Neplatne cislo kancelare.'
        stupne[x] += 1
        stupne[y] += 1
        DS.union(x, y)

    assert max(stupne) <= K, 'Z nektere kancelare vede prilis mnoho potrubi.'
    assert len(set(DS.color)) == 1, 'Pridana potrubi neprepojila vsechny kancelare.'

    return # all OK

###############################################################################################

input_file = open(argv[1],'r')
N, K, P = [ int(_) for _ in input_file.readline().split() ]
DS = DisjointSet(N)
stupne = [ 0 for n in range(N) ]
for p in range(P):
    x, y = [ int(_) for _ in input_file.readline().split() ]
    DS.union(x, y)
    stupne[x] += 1
    stupne[y] += 1

our_output_tokens = open(argv[2],'r').read().split()
is_solvable = (our_output_tokens[0] != '-1')

try:
    process_their_output(N, K, P, DS, stupne, is_solvable)
except Exception as error_message:
    print(0)
    print(error_message, file=stderr)
    exit(0)

print('1.0')
