This page is still under construction.

Parts of this page are still being built. What you see may change.

Driving Out the Piggies

Time limit1sMemory limit128 MB

Summary
A bomb starts at city 1 of an undirected graph, detonates at each visit with probability P/Q and otherwise moves to a random neighbor; find the detonation probability for every city.
Level

Medium6 of 10

Topics
Probability, Graph, Dynamic programming, Math
Solved
No attempts yet

Problem

The Cows have built a randomized stink bomb to drive the Piggies out of their land. The Piggy civilization has NN cities, numbered 11 through NN, connected by MM bidirectional roads. Each road joins two different cities, and city 11 is guaranteed to be connected to at least one other city.

The stink bomb is placed in city 11. Every hour — including the very first one — the bomb sits in some city and does exactly one of two things:

  • With probability PQ\frac{P}{Q} it detonates, polluting the city it currently occupies, and the process stops.
  • Otherwise (with probability 1−PQ1 - \frac{P}{Q}) it does not detonate. It then chooses one of the roads leaving its current city uniformly at random and travels along it to the neighboring city. Every road leaving a city is equally likely to be chosen.

Because the bomb wanders at random, the Cows want to know, for every city, the probability that the bomb eventually detonates there (polluting it).

For example, suppose there are two cities joined by a single road, and the bomb — starting in city 11 — detonates with probability 12\frac{1}{2} each time it enters a city:

1--2

Writing each possible journey as the sequence of cities the bomb visits (it detonates in the last city listed), the journeys are:

1
1-2
1-2-1
1-2-1-2
1-2-1-2-1
...

The bomb detonates in city 11 exactly on the journeys that pass through an odd number of cities (1; 1-2-1; 1-2-1-2-1; and so on). A journey through kk cities occurs with probability (12)k\left(\frac{1}{2}\right)^k: the bomb must fail to detonate in each of the first k−1k-1 cities (probability 1−12=121-\frac{1}{2}=\frac{1}{2} each) and then detonate in the kk-th (probability 12\frac{1}{2}). Summing the odd-numbered terms gives the probability of detonating in city 11:

12+(12)3+(12)5+⋯=23≈0.666666667\frac{1}{2} + \left(\frac{1}{2}\right)^3 + \left(\frac{1}{2}\right)^5 + \cdots = \frac{2}{3} \approx 0.666666667

so the probability of detonating in city 22 is 13≈0.333333333\frac{1}{3} \approx 0.333333333.

Input

  • Line 1: four space-separated integers NN, MM, PP, and QQ (2≤N≤3002 \le N \le 300; 1≤M≤448501 \le M \le 44850; 1≤P≤1061 \le P \le 10^6; 1≤Q≤1061 \le Q \le 10^6; P≤QP \le Q).
  • Lines 2 to M+1M+1: each line contains two space-separated integers AjA_j and BjB_j (1≤Aj≤N1 \le A_j \le N; 1≤Bj≤N1 \le B_j \le N; Aj≠BjA_j \ne B_j), describing a bidirectional road between cities AjA_j and BjB_j.

Output

Print NN lines. On line ii, print the probability that city ii is polluted, written with exactly 99 digits after the decimal point.

Examples3

  1. Example 1

    Input
    2 1 1 2
    1 2
    
    Expected output
    0.666666667
    0.333333333
    
  2. Example 2

    Input
    3 2 1 2
    1 2
    2 3
    
    Expected output
    0.583333333
    0.333333333
    0.083333333
    
  3. Example 3

    Input
    3 3 1 3
    1 2
    2 3
    1 3
    
    Expected output
    0.500000000
    0.250000000
    0.250000000