Under construction

Still being built. Things may change

Earthquake Damage 2

Time limit1sMemory limit128 MB

Summary
Given an undirected graph and a set of vertices that cannot reach the barn, find the minimum number of other vertices to remove so that exactly those vertices are separated from vertex 1.
Level

Hard8 of 10

Topics
Graph, BFS, Greedy, Implementation
Solved
No attempts yet

Problem

An earthquake has struck Farmer John's farm! The earthquake has damaged some of the pastures so that they are impassable. Remarkably, none of the cowpaths was damaged.

As usual, the farm is modeled as a set of PP (1≤P≤30001 \le P \le 3000) pastures numbered 1…P1 \dots P, connected by a set of CC (1≤C≤200001 \le C \le 20000) undirected cowpaths numbered 1…C1 \dots C. Cowpath ii connects pastures aia_i and bib_i (1≤ai≤P1 \le a_i \le P; 1≤bi≤P1 \le b_i \le P). A cowpath might connect a pasture to itself, and two pastures might be connected by more than one cowpath. The barn is located in pasture 11.

A total of NN (1≤N≤P1 \le N \le P) cows, each in a different pasture, sequentially contact Farmer John by phone. Cow jj sends an integer report reportjreport_j (2≤reportj≤P2 \le report_j \le P) meaning that pasture reportjreport_j is undamaged, but the calling cow cannot return to the barn from pasture reportjreport_j because every path back to the barn passes through at least one damaged pasture.

After all cows have reported in, determine the minimum number of pastures that could be damaged. The barn (pasture 11) and every reported pasture are guaranteed to be undamaged.

Input

  • Line 11: Three space-separated integers: PP, CC, and NN.
  • Lines 2…C+12 \dots C+1: Line i+1i+1 describes cowpath ii with two integers aia_i and bib_i.
  • Lines C+2…C+N+1C+2 \dots C+N+1: Line C+1+jC+1+j contains a single integer reportjreport_j.

Output

  • Line 11: One integer, the minimum number of damaged pastures.

Examples3

  1. Example 1

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

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

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