CF113D.Museum
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
One day as Petya and his friend Vasya were having one of their numerous trips, they decided to visit a museum castle. The museum has a specific shape: it consists of n rooms connected with m corridors so that one can access any room from any other one.
After the two friends had a little walk around the museum, they decided to split and watch the pieces of art each of them found interesting. They agreed to meet in one of the rooms at six p.m. However, they forgot one quite essential thing: they didn't specify the place to meet and when the time came, they started to rush about the museum looking for each other (they couldn't call each other as roaming made a call's cost skyrocket).
Yet, even despite the whole rush, they couldn't get enough of the pieces of art, that's why each of them has the following strategy: each minute he make a decision where to go — with probability p__i he doesn't move to any other place during this minute (i.e. he stays in the room). With probability 1 - p__i he equiprobably choose one of the adjacent rooms and went there along the corridor. Here i is the ordinal number of the current room. Building was expensive in ancient times, that's why each corridor connected two different rooms, and any two rooms had no more than one corridor between them.
The boys act simultaneously. As the corridors are dark, it is impossible to meet there; however, one can walk along the corridors in both directions (besides, the two boys can be going through the same corridor simultaneously without meeting). The boys act like that until they meet each other. More formally, the two friends meet when at some moment of time both of them decided to appear in the same room.
For each room find the probability that the boys will meet there considering that at 6 p.m. they are positioned in rooms a and b correspondingly.
一天,佩蒂亚和他的朋友瓦夏正在进行他们众多旅行中的一次,他们决定参观一座博物馆城堡。这座博物馆具有特定的结构:它由 n 个房间和 m 条走廊组成,任意两个房间之间均可互相到达。
两位朋友在博物馆内稍作游览后,决定分开行动,各自欣赏自己感兴趣的展品。他们约定于下午六点在某个房间会合。然而,他们忽略了一个非常关键的问题:他们并未事先约定具体的会合地点。因此,当时间到来时,他们只得在博物馆中四处奔走,试图寻找彼此(由于漫游费用极高,他们无法通过电话联系)。
尽管如此匆忙,他们仍对展品意犹未尽,因此各自采取如下策略:每一分钟,他们独立地作出移动决策——以概率 pi,他在此分钟内不前往其他任何地方(即停留在当前房间);以概率 1−pi,他从与当前房间相邻的所有房间中等概率地随机选择一个,并沿走廊前往该房间。其中 i 表示当前所在房间的编号。由于古代建筑成本高昂,每条走廊均连接两个不同的房间,且任意两个房间之间至多只有一条走廊。
两名少年同时行动。由于走廊光线昏暗,他们无法在走廊中相遇;但走廊是双向通行的(此外,两名少年可同时沿同一条走廊相向而行或同向而行,而不会相遇)。他们持续按此方式行动,直至彼此相遇为止。更准确地说,当在某一时刻,两人同时决定出现在同一个房间时,即视为相遇。
对于每个房间,请计算:若在下午六点时,佩蒂亚位于房间 a、瓦夏位于房间 b,则两人最终在该房间相遇的概率。
输入格式
The first line contains four integers: n (1 ≤ n ≤ 22), representing the numbers of rooms; m
, representing the number of corridors; a, b (1 ≤ a, b ≤ n), representing the numbers of Petya's and Vasya's starting rooms correspondingly.
Next m lines contain pairs of numbers — the numbers of rooms connected by a corridor. Next n lines contain probabilities p__i (0.01 ≤ p__i ≤ 0.99) with the accuracy of up to four digits after the decimal point — the probability to stay in room i.
It is guaranteed that every room can be reached from every other room by corridors.
第一行包含四个整数:$ n ( 1 \leq n \leq 22 ),表示房间的数量; m $
,表示走廊的数量;$ a 、 b ( 1 \leq a, b \leq n $),分别表示佩蒂亚和瓦夏的起始房间编号。
接下来的 $ m $ 行,每行包含一对数字——由走廊相连的两个房间的编号。再接下来的 $ n $ 行,每行包含一个概率 $ p_i ( 0.01 \leq p_i \leq 0.99 $),保留小数点后四位精度——表示停留在第 $ i $ 个房间的概率。
保证任意两个房间之间均可通过走廊互相到达。
输出格式
In the only line print n space-separated numbers, the i-th number should represent the probability that the friends meet in the i-th room with absolute or relative error of no more than 10 - 6.
在唯一的一行中输出 n 个以空格分隔的数字,其中第 i 个数字表示朋友们在第 i 个房间相遇的概率,要求绝对或相对误差不超过 10−6。
输入输出样例
输入#1
2 1 1 2 1 2 0.5 0.5
输出#1
0.5000000000 0.5000000000
输入#2
4 4 1 2 1 2 2 3 3 4 4 1 0.5 0.5 0.5 0.5
输出#2
0.3333333333 0.3333333333 0.1666666667 0.1666666667
说明/提示
In the first sample the museum is symmetric. That means the probabilities to meet in rooms 1 and 2 are equal. And their sum equals to one. So, each probability equals 0.5.
在第一个样例中,博物馆是对称的。这意味着在 1 号房间和 2 号房间相遇的概率相等,且它们的和为 1。因此,每个概率均为 0.5。
输入解题思路,AI测评打分。不知道怎么写?