Do Not Disturb!
Time limit1sMemory limit128 MB
Two people wander a graph at random each step, and you must find the expected time until both reach node C at once.
- Level
Medium7 of 10
- Topics
- Probability, Matrix, Graph
- Solved
- No attempts yet
Problem
Nicole and Noura work on the media team of a regional contest. While the contest runs, Noura walks the contest hall photographing the teams, meets Nicole and hands the photos over, and Nicole posts them on the contest's Facebook page. So that the teams are left alone, the contest director fixed a set of corridors the two may walk while they do this. The corridors cross one another and together they form a graph.
Formally, you are given a graph whose nodes are the crossing points and the endpoints of the corridors, together with bidirectional edges joining the nodes. Two nodes are neighbors when an edge joins them. Walking along one edge takes unit of time.
When the contest starts, Nicole stands on node and Noura stands on node . The two nodes may be the same. During each unit of time each of them picks one neighboring node and moves there, or picks to stay on the current node for the whole unit. A node with neighbors gives choices, and each choice is picked with the same probability . The two of them pick independently of each other.
The machine used for uploading stands on node . Compute the expected number of time units until the two of them stand on node at the same moment for the first time.
Input
The first line has one integer , the number of test cases.
The first line of each test case has two space separated integers and , the number of nodes and the number of edges.
The second line has three space separated integers , and . is the starting node of Nicole, is the starting node of Noura, and is the index of the node where they have to meet.
Each of the next lines has two space separated integers and , meaning that an undirected edge joins node and node . At most one edge joins any pair of nodes, and no edge joins a node to itself.
- , , , and are zero based indices between and , and .
Output
For each test case print on a single line the expected number of time units rounded to three decimal places. If the two of them can never stand on node at the same moment, print Impossible instead.
In every test the exact expected value is at least away from a rounding boundary, meaning a value whose fourth decimal digit is with only zeros after it. The rounded answer is therefore unique.