#P17323. [ICPC 2018 Nanjing R] Frank

    ID: 16803 Type: RemoteJudge 1000ms 512MiB Tried: 0 Accepted: 0 Difficulty: 9 Uploaded By: Tags>2018Special Judge期望高斯消元ICPC南京

[ICPC 2018 Nanjing R] Frank

题目描述

Frank likes to travel. However, he doesn't prefer a fully-planned trip. Instead, he enjoys traveling from one city to another randomly.

Frank's favorite country is Country Meow because the roads in the country are complicated.

Country Meow has NN cities, indexed with numbers from 00 to N−1N-1, and there are MM unidirectional roads. The ii-th road can be denoted by (ai,bi)(a_i, b_i), which means it starts from city aia_i and ends in city bib_i, and does not pass through any other cities. Interestingly, there may be roads with ai=bia_i=b_i, or several roads with the same starting and ending cities. The roads are built in a way such that for any two cities AA and BB, one can travel from AA to BB through these roads.

Frank is planning QQ trips to Country Meow. Each plan is an ordered list of cities C=(c0,c1,⋯ ,cK−1)C=(c_0, c_1, \cdots, c_{K-1}) such that ci≠ci+1c_i\neq c_{i+1} for all 0≤i≤K−20\leq i \leq K-2.

On a trip with a plan CC, Frank will:

  1. Go to city c0c_0.
  2. Choose a road uniformly at random from all roads whose starting city is Frank's current city.
  3. Follow the chosen road to the next city.
  4. If CC is a subsequence of the current visited cities sequence, then the trip is finished. Otherwise, go to step 2.

(A sequence AA is a subsequence of another sequence BB if one can delete some or no elements from BB without changing the order and obtain AA.)

However, each road requires a toll of 11 dollar. Frank wants to know the expected value of the total amount of fees he spent on each trip. Can you help him?

输入格式

The first line contains three positive integers N,M,QN,M,Q (3≤N≤400,M≤4×105,Q≤4003\leq N\leq 400, M\leq 4\times 10^ 5, Q\leq 400).

The following MM lines describe the roads in the Country Meow. Each of them contains two integers ai,bia_i, b_i (0≤ai,bi<N0\leq a_i,b_i<N) —\text{---} the starting and ending cities of the ii-th road.

The following 2Q2Q lines describe the plans Frank made. Each two lines describe a plan. The first contains an integer KK (2≤K≤5002\leq K\leq 500) —\text{---} the length of the city list; the second contains KK integers c0,c1,⋯ ,cK−1c_0, c_1,\cdots, c_{K-1} (0≤ci<N,ci≠ci+10\leq c_i<N, c_i\neq c_{i+1}) —\text{---} the city list in the plan.

输出格式

For each plan, print a single real number in one line —\text{---} the expected value of the total amount of fees on the corresponding trip.

Your answer is considered correct if the absolute or relative error between each number in your output and the corresponding one in jury's answer does not exceed 10−810^{-8}. Formally, let your answer be aa, and the jury's answer be bb. Your answer is considered correct if ∣a−b∣max⁡(1,∣b∣)≤10−8\frac{|a - b|}{\max(1, |b|)} \le 10^{-8}.

It is guaranteed that for any plan, the answer is less than 10710^7

3 4 3
0 1
1 2
2 0
2 1
2
1 0
4
0 2 0 1
3
2 1 2
4.0000000000
6.0000000000
2.5000000000