Problem:
Network Reliability

An undirected graph is given.
Each edge of the graph disappears with a constant probability.
Calculate the probability with which the remained graph is connected.

Input

The first line contains three integers N (1 \leq N \leq 14), M (0 \leq M \leq 100) and P (0 \leq P \leq 100), separated by a single space.
N is the number of the vertices and M is the number of the edges. P is the probability represented by a percentage.

The following M lines describe the edges.
Each line contains two integers v_i and u_i (1 \leq u_i, v_i \leq N).
(u_i, v_i) indicates the edge that connects the two vertices u_i and v_i.

Output

Output a line containing the probability with which the remained graph is connected.
Your program may output an arbitrary number of digits after the decimal point. However, the absolute error should be 10^{-9} or less.

Sample Input 1

3 3 50
1 2
2 3
3 1

Output for the Sample Input 1

0.500000000000

Sample Input 2

3 3 10
1 2
2 3
3 1

Output for the Sample Input 2

0.972000000000

Sample Input 3

4 5 50
1 2
2 3
3 4
4 1
1 3

Output for the Sample Input 3

0.437500000000

Solution in Ruby (judge verdict: Runtime Error)


n, m, q = gets.split.map(&:to_i)

prob = {}
(1..m).each do
    i, j = gets.split.map(&:to_i) 
    (prob[i] ||= Hash.new(1.0))[j] = q / 100.0
    (prob[j] ||= Hash.new(1.0))[i] = q / 100.0
end

require 'set'

def f(prob)
    return 1.0 if prob.size == 1

    if prob.size == 1 + prob.values.map(&:size).inject(:+) / 2
        return prob.keys.combination(2).map {|i, j| prob[i].key?(j) ? 1 - prob[i][j] : 1}.inject(:*)
    end

    i = prob.keys.min_by{|i| prob[i].size}
    j = prob[i].keys.min_by{|j| prob[j].size}

    new_prob = {}
    prob.each {|k, h| new_prob[k] = h.dup}
    new_prob[i].delete(j)
    new_prob[j].delete(i)

    
    reached = disconnected?(new_prob)
    if reached
        g1 = {}
        new_prob.each {|k, h| g1[k] = new_prob[k].dup if reached.include?(k)}
        g2 = {}
        new_prob.each {|k, h| g2[k] = new_prob[k].dup if !reached.include?(k)}
        return (1.0 - prob[i][j]) * f(g1) * f(g2)
    else
        return prob[i][j] * f(new_prob) + (1.0 - prob[i][j]) * f(contract(prob, i, j))
    end
end

def contract(prob, i, j)
    new_prob = {}
    new_prob[j] = prob[j].dup
    new_prob[j].delete(i)
    prob.each do |k, h|
        next if k == i or k == j
        new_prob[k] = h.dup
        q = h[i]
        new_prob[k].delete(i)
        new_prob[k][j] *= q
        new_prob[j][k] = new_prob[k][j]
    end
    new_prob
end

require 'set'
def disconnected?(prob)
    i = prob.keys[0]
    reached = Set[i]
    queue = [i]
    until queue.empty?
        i = queue.shift
        prob[i].each do |j, _|
            next if reached.include?(j)
            reached << j
            queue << j
        end
    end
    return reached.size == prob.size ? nil : reached
end

printf("%.12f\n", f(prob))