T1. refract
Incomplete idea :
Take Sample For Example :

The sample also equals to :
1 2 0.5000
2 1 0.5000
Let the final damage of hero 1 and 2 A_1 , A_2 .
In the first refraction , A_1 \rightarrow 0.5A_1 , A_2 \rightarrow 0.5A_1+A_2 .
In the second refraction, A_2 \rightarrow 0.25A_1+0.5A_2 , A_1 \rightarrow 0.75A_1+0.5A_2 .
To compute the final damage, we can suppose that after 2 refractions, both A_1 and A_2 do not change.
So, we can get 1 equation : 0.5A_2 = 0.25A_1 , i.e. A_1 = 2A_2 .
And we can know that during 1 refraction, the total damage do not change.
So, we can get an another equation : A_1 + A_2 = 1
Solve the 2 equations, we can get A_1=\frac{2}{3} , A_2=\frac{1}{3} .
Compare it with standard output :

The answer we get is correct.
So, based on this example, I got some ideas to compute it.
- If some refractions form a chain, directly compute it.
- If some refractions form a cycle, compute the coefficients and then solve equations.
However, there are 2 serious problems :
- I cannot solve equations.
- There are still many possibilities I did not consider.
- Such as:

So, I finally gave it up.