This page is still under construction.

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

Snow Chaos

Time limit1sMemory limit1024 MB

Summary
Given a path of n stations with s snowy edges and m travel requests, choose at most p snowy edges to clear so the number of requests whose endpoints become connected is maximized.
Level

Medium7 of 10

Topics
Dynamic programming, Intervals, Prefix sum, Brute force
Solved
No attempts yet

Problem

A snowstorm has moved in and traffic is in chaos. On top of that, parts of the railway track are snowed over, which has stopped all train traffic. This is of course not good, since crowds of travelers are now stuck at their stations with no way to get anywhere. Fredrika has therefore been tasked with clearing the snow between the stations before rush hour begins and the disaster is a fact.

The railway track has no branches at all and has nn stations, numbered from 11 to nn in the order they appear on the track (so station ii comes just before station i+1i+1). There are thus n−1n - 1 stretches between the stations. Of these, ss are covered in snow.

Fredrika is a little worried, because she has worked out that she only has time to clear the snow from pp stretches. To make the best of the situation, Fredrika decides to choose the stretches that let as many as possible of the waiting travelers get where they want to go. To help her, she has the answers from a survey she sent to everyone who is waiting, in which they answered which stations they want to travel between.

Assuming Fredrika chooses the stretches optimally, calculate how many waiting travelers will be able to travel once she is done.

Note that trains can only run on stretches without snow. Every station has trains parked at it, so every stretch without snow will be able to carry traffic, even if the stations cannot be reached from the endpoints of the track. Train traffic is completely stopped until Fredrika is done, so travelers who had a snow-free route from the start are also counted in the answer.

Figure 1: Sample 1

Input

The first line contains four integers, 2≤n≤2002 \le n \le 200, 1≤m≤1000001 \le m \le 100000, 0≤s,p≤n−10 \le s, p \le n - 1: the number of stations, the number of travelers, the number of snowed-over stretches, and the number of stretches Fredrika has time to plow.

Then follow mm lines, where line ii contains two integers 1≤ai≠bi≤n1 \le a_i \not= b_i \le n, the stations where traveler ii wants to start and end.

Then follow ss lines, where line jj contains an integer 1≤cj≤n−11 \le c_j \le n - 1, the station that lies just before snowed-over stretch jj. A stretch appears at most once in this list.

Output

Your program should print a single integer: the largest number of travelers who can complete their journeys by plowing at most pp stretches.

Examples1

  1. Example 1

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