A wilderness rescue network is made up of numbered relay towers that communicate by requesting direct radio links with one another. Over time, towers send link requests to other towers; the same ordered pair of towers may appear more than once in the request log if the request was repeated, but only the tower pair matters, not how many times it repeats. Separately, a log of approved links records every pair of towers whose link was approved -- and, again, the same pair may appear more than once in that log.
You are given both logs. Compute the network's overall approval rate: the number of distinct ordered tower pairs that appear anywhere in the approved-links log, divided by the number of distinct ordered tower pairs that appear anywhere in the requests log. The two logs are compared purely by their own distinct-pair counts -- an approved pair is not required to also appear in the request log, so the rate can exceed 1.00. If no requests were ever sent, report a rate of 0.00.
A pair is ordered: a request (a, b) and an approval (b, a), with the two towers swapped, are treated as different pairs. Round the final result to exactly two decimal places, rounding half up (so a value like 0.125 rounds to 0.13).
Line 1: an integer n -- the number of link-request log entries.
Next n lines: two integers a b -- a link request from tower a to tower b.
Next line: an integer m -- the number of approved-link log entries.
Next m lines: two integers c d -- an approved link between tower c and tower d.
A single line containing the approval rate, formatted with exactly two digits after the decimal point (for example 0.75, 1.00, 0.00, 1.50).
Example 1
Input
5 1 2 1 3 1 4 2 3 3 4 5 3 1 1 3 2 3 3 4 3 4
Expected
0.80
Explanation
The request log contains 5 distinct ordered pairs: (1,2), (1,3), (1,4), (2,3), (3,4). The approval log contains the pairs (3,1), (1,3), (2,3), (3,4), (3,4) -- the pair (3,4) repeats twice but counts once, giving 4 distinct approved pairs. The rate is 4/5 = 0.80.
Example 2
Input
0 2 5 6 7 8
Expected
0.00
Explanation
No link requests were ever logged (n = 0), so the denominator is zero and the rate is reported as 0.00 regardless of the two approvals that were logged.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →