ITAI Virus
InterviewTime limit1sMemory limit256 MB
Count the initially infected cities plus every city directly joined to one by a single road.
- Level
Easy2 of 10
- Topics
- Graph, Implementation
- Solved
- No attempts yet
Problem
Insane Transferable Abnormal Illness, ITAI for short, is a viral disease first found in the southern part of a city. A person who catches the virus screams "Itai, itai!" without stopping.
When the virus appears in a city it splits in two and travels along every road that touches that city. The city it started from keeps the virus as well. The ITAI virus is weak: once it reaches another city it degenerates into a weak virus that never spreads again.
A country has cities, numbered 1 to , and roads. The Ministry of Health inspected the country and found the virus in cities. Every one of those cities holds a new virus that can still spread.
Find how many cities hold the virus after all of the spreading is over.
Input
The first line has the number of test cases . ()
Each test case is given in the following format.
- The first line has the number of cities , the number of roads , and the number of cities where the virus was found . (, , )
- The next lines each have two integers and describing a road. (, ) The road connects city and city in both directions. Several roads may connect the same pair of cities, and may equal .
- The next line has the numbers of the cities where the virus was found. If is 0, this line is empty.
Output
For each test case, print the number of cities that hold the virus on its own line.
Hint
The cities that hold the virus are the cities where the virus was found together with the cities joined to them by a single road. A city that can only be reached by crossing two or more roads stays clean.