Under construction

Still being built. Things may change

Earthquake Damage

Time limit1sMemory limit128 MB

Summary
Given a graph and reports that certain damaged pastures cannot reach the barn, find the minimum total number of pastures that cannot return to the barn.
Level

Hard8 of 10

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

Problem

An earthquake has struck Farmer John's farm in Wisconsin! The quake damaged some pastures so that they can no longer be crossed. Remarkably, none of the cowpaths was damaged.

The farm is a set of PP pastures numbered 1…P1 \ldots P (1≤P≤30,0001 \le P \le 30{,}000), connected by CC undirected cowpaths numbered 1…C1 \ldots C (1≤C≤100,0001 \le C \le 100{,}000). Cowpath ii joins pastures aia_i and bib_i (1≤ai≤P1 \le a_i \le P; 1≤bi≤P1 \le b_i \le P). A cowpath may join a pasture to itself, and two pastures may be joined by more than one cowpath. The barn is in pasture 11.

NN cows, each in a different pasture (1≤N≤P1 \le N \le P), phone Farmer John one after another, each reporting a single integer reportj\text{report}_j (2≤reportj≤P2 \le \text{report}_j \le P). The report means that pasture reportj\text{report}_j is undamaged, yet the calling cow cannot get back to the barn from it because no path avoiding damaged pastures exists.

After every cow has reported in, determine the minimum number of pastures from which it is impossible to return to the barn (counting the impassable damaged pastures themselves).

Input

  • Line 1: Three space-separated integers: PP, CC, and NN
  • Lines 2…C+12 \ldots C+1: Line i+1i+1 describes cowpath ii with two integers aia_i and bib_i.
  • Lines C+2…C+N+1C+2 \ldots C+N+1: Line C+1+jC+1+j contains a single integer reportj\text{report}_j.

Output

  • Line 1: A single integer, the minimum number of pastures from which a cow cannot return to the barn (including the damaged pastures themselves).

Hint

For example, along the path 1−2−3−41-2-3-4, damaging pasture 22 leaves the cows in pastures 22, 33, and 44 unable to return to the barn.

Examples1

  1. Example 1

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