In the event of technical difficulties with Szkopuł, please contact us via email at [email protected].
If you would like to talk about tasks, solutions or technical problems, please visit our Discord servers. They are moderated by the community, but members of the support team are also active there.
Psst... Ruszyły zawody olimpiady informatycznej dla uczniów szkół podstawowych i średnich. Zadania na tych konkursach są bardzo podobne do zadań, które rozwiązujesz, tutaj, na Szkopule. Zobacz więcej:
- dla uczniów szkół podstawowych: oij.edu.pl/start/
- dla uczniów szkół średnich: oi.edu.pl/l/jak_zaczac/
Byteland is a small country, with cities connected by
bidirectional roads.
From each city there is just one way of reaching every other city
using the road network, which causes severe traffic jams.
For this reason several highways have been built; each highway
connects some pair of cities.
By a route we mean a sequence of roads and/or highways.
All cities on a route should be distinct.
For each pair of cities , there exists exactly one route
which does not use any highway; we call such a route the main route between and .
People going from a city to a city
can either choose the main route
or use some highway.
In the latter case the route cannot intersect the main route except for the cities and
and must contain exactly one highway.
Your task is to calculate the number of routes people can take
between given pairs of cities.
Input
The first line of input contains a single integer
() - the number of cities in Byteland.
Cities are numbered from to .
Each of the next lines contains two integers , () meaning that cities and
are connected by a road.
The next line contains an integer () -
the number of highways.
Each of the next lines contains a description of a single highway.
The next line contains an integer ()
- the number of queries.
Each of the next lines contains a description of a query.
Both highways and queries are given in the same format as the roads.
Output
Your program should output exactly lines.
The -th line should contain the number of routes
in the -th query.