Given an undirected graph, a set of source vertices, and a set of airport vertices, count the vertices that every source-to-airport path must pass through.
Hard8GraphDFSNo attempts yetTime limit2sMemory limit128 MBCoders High hired a group of strong programmers and built an intrusion detection system. The company has many people who know algorithms and security well, so results came quickly.
One day the engineers at Coders High detected an intrusion attempt against the company. They identified every place the attack may have been launched from. The suspects are now trying to escape to an airport.
Assume the suspects are staying at one of the places where the attack may have been launched, and that they reach one of the airports within a finite amount of time. There is no guarantee that they take a shortest route.
Call a place A a checkpoint candidate when it has the following property.
So if you wait at a checkpoint candidate, the suspects pass through it sooner or later.
You know every place and every road that joins them, and the engineers handed you the list of places where the attack may have been launched together with the list of places that have an airport. Compute how many checkpoint candidates there are and which places they are.
The first line contains the number of places N (2≤N≤100000) and the number of roads M (1≤M≤200000), separated by a space. The places are numbered from 1 to N.
Each of the next M lines describes one road. The i-th of these lines contains the numbers of the two places the road joins, ai and bi (1≤ai,bi≤N, ai=bi), separated by a space.
The next line contains the number of places where the attack may have been launched, S (1≤S≤N−1), and the number of places that have an airport, E (1≤E≤N−1), separated by a space.
The next line contains the numbers of the places where the attack may have been launched, s1,s2,…,sS, separated by spaces. The last line contains the numbers of the places that have an airport, e1,e2,…,eE, separated by spaces. The si are pairwise different, and the ei are pairwise different.
All places are connected directly or indirectly. That is, from any place there is always a route to any other place. Also there are no indices i=j with (ai,bi)=(aj,bj), so at most one road joins any two places.
On the first line, print the number of checkpoint candidates.
On the second line, print the checkpoint candidates in increasing order of their numbers, separated by single spaces. If there is no checkpoint candidate, print an empty second line.
A place si where the attack may have been launched and a place ei that has an airport can also be checkpoint candidates.