Problem Statement: Anya and Vanya have categorized a set of jokes into disjoint subsets.…
- User
Problem Statement:
Anya and Vanya have categorized a set of jokes into disjoint subsets. Anya uses
Msets, and Vanya usesKsets. The task is to compute the "humor compatibility score" between Anya and Vanya, using a formula that compares the observed number of jokes placed into the same sets by both of them against an expected number of jokes based on independent distributions.The steps are as follows:
-
Anya and Vanya each divide a collection of
Njokes intoMandKnon-overlapping sets, respectively. -
For each pair of sets
(A, B), whereAis a set from Anya's categorization andBis a set from Vanya's categorization:- Compute the real observed number of jokes,
o(A, B), that both Anya and Vanya placed into those sets. - Compute the expected number of jokes,
e(A, B), assuming Anya's and Vanya's categorizations are independent.
- Compute the real observed number of jokes,
-
The humor compatibility score is calculated as: [ \sum_{(A, B) : e(A,B) > 0} \frac{(o(A,B) - e(A,B))^2}{e(A,B)} ] where
e(A,B)is the expected value of jokes for the pair(A, B). -
You need to output a floating-point number, the humor compatibility score, with a precision up to
10^{-6}.
Input Format:
- The first line contains two integers
MandK(1 ≤ M, K ≤ 10^5), which are the number of sets Anya and Vanya use. - The second line contains an integer
N(1 ≤ N ≤ 10^5), the number of jokes. - The next
Nlines each contain two integersa_iandb_i(1 ≤ a_i ≤ M,1 ≤ b_i ≤ K), indicating the set to which Anya and Vanya respectively assign thei-th joke.
Output Format:
- Output a single floating-point number representing the humor compatibility score between Anya and Vanya, with an absolute or relative error not exceeding
10^{-6}.
-
- Assistant