NOI Contest Archive

Archive / 2020 / April 2020

Bat Virus

Medium · National Olympiad in Informatics Sri Lanka - April 2020

Neverland is a country with N cities (indexed from 0 to N-1). The cities are connected to each other by a network of R two-way roads.

Two cities are considered to be neighbors if they’re directly connected by a two-way road.

To an unfortunate turn of events, the country got struck by a mysterious bat virus. Initially (on day D1), patients with the virus were reported from some cities in the country. The virus spreads in a weird, but interesting way.

Consider a city C0 , with C1 , C2 , C3 , C4 , …, Ct neighbor cities. On day Di , let’s say there are P0 , P1 , P2 , P3 , P4 , …, Pt patients corresponding to each city. Then number of patients in C0 on day \(D_{(i+1)} = max( C_0, \frac{C_1}{2}, \frac{C_2}{2}, \frac{C_3}{2}, \frac{C_4}{2}, ..., \frac{C_t}{2})\)

Given the road network and initial conditions of virus, your task is to find the maximum number of bat-virus patients that will be recorded in the country (Pmax), and the number of days (Dmax) it will take for Pmax to appear first.

Input Format

First line contains two space seperated integers N and R. (Number of Cities, and the number of two-way roads)
R lines follow, with i th line having two space seperated integers Si and Ei , the index of two cities connected by the road Ri .
Next line contains a single integer M, the initial number of cities where the virus appeared.
M lines follow, with j th of them having two space seperated integers Cj and Pj , the index of the city, and the number of patients reported respectively.

Output Format

Two integers, Dmax and Pmax

Constraints

Limits

Sample Input 0

6 5
0 1
1 2
2 3
3 4
4 5
2
0 100
4 5

Sample Output 0

6 196