CF1045D.Interstellar battle
提高+/省选-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
In the intergalactic empire Bubbledom there are N planets, of which some pairs are directly connected by two-way wormholes. There are N−1 wormholes. The wormholes are of extreme religious importance in Bubbledom, a set of planets in Bubbledom consider themselves one intergalactic kingdom if and only if any two planets in the set can reach each other by traversing the wormholes. You are given that Bubbledom is one kingdom. In other words, the network of planets and wormholes is a tree.
However, Bubbledom is facing a powerful enemy also possessing teleportation technology. The enemy attacks every night, and the government of Bubbledom retakes all the planets during the day. In a single attack, the enemy attacks every planet of Bubbledom at once, but some planets are more resilient than others. Planets are number 0,1,…,N−1 and the planet i will fall with probability pi. Before every night (including the very first one), the government reinforces or weakens the defenses of a single planet.
The government of Bubbledom is interested in the following question: what is the expected number of intergalactic kingdoms Bubbledom will be split into, after a single enemy attack (before they get a chance to rebuild)? In other words, you need to print the expected number of connected components after every attack.
在星际帝国“泡泡国”(Bubbledom)中,共有 N 颗行星,其中某些行星对之间由双向虫洞直接相连。虫洞总数为 N−1 条。这些虫洞在泡泡国具有极高的宗教意义:泡泡国中的一组行星被视为一个星际王国,当且仅当该组中任意两颗行星均可通过虫洞相互到达。已知泡泡国整体构成一个星际王国。换言之,行星与虫洞构成的网络是一棵树。
然而,泡泡国正面临一个同样掌握传送技术的强大敌人的威胁。敌人每晚发动一次攻击,而泡泡国政府则于白昼夺回所有行星。在单次攻击中,敌人同时攻击泡泡国的所有行星,但不同行星的抗打击能力不同:编号为 0,1,…,N−1 的行星 i 在一次攻击中失守的概率为 pi。在每次夜晚来临前(包括第一次攻击前),泡泡国政府会对恰好一颗行星的防御进行加强或削弱。
泡泡国政府关注如下问题:在单次敌方攻击之后(但在政府重建之前),泡泡国被分割成的星际王国的期望数量是多少?换句话说,你需要输出每次攻击后图中连通块数量的期望值。
输入格式
The first line contains one integer number N (1≤N≤105) denoting the number of planets in Bubbledom (numbered from 0 to N−1).
The next line contains N different real numbers in the interval [0,1], specified with 2 digits after the decimal point, denoting the probabilities that the corresponding planet will fall.
The next N−1 lines contain all the wormholes in Bubbledom, where a wormhole is specified by the two planets it connects.
The next line contains a positive integer Q (1≤Q≤105), denoting the number of enemy attacks.
The next Q lines each contain a non-negative integer and a real number from interval [0,1], denoting the planet the government of Bubbledom decided to reinforce or weaken, along with the new probability that the planet will fall.
第一行包含一个整数 N(1≤N≤105),表示泡泡国(Bubbledom)中行星的数量(编号为 0 到 N−1)。
第二行包含 N 个互不相同的实数,均在区间 [0,1] 内,保留两位小数,表示对应行星坍塌的概率。
接下来的 N−1 行描述泡泡国中的所有虫洞,每个虫洞由其所连接的两颗行星指定。
下一行包含一个正整数 Q(1≤Q≤105),表示敌方攻击的次数。
接下来的 Q 行每行包含一个非负整数和一个区间 [0,1] 内的实数,分别表示泡泡国政府决定加强或削弱的行星编号,以及该行星坍塌的新概率。
输出格式
Output contains Q numbers, each of which represents the expected number of kingdoms that are left after each enemy attack. Your answers will be considered correct if their absolute or relative error does not exceed 10−4.
输出包含 Q 个数字,每个数字表示每次敌方攻击后剩余王国的期望数量。若你的答案的绝对误差或相对误差不超过 10−4,则视为正确。
输入输出样例
输入#1
5 0.50 0.29 0.49 0.95 0.83 2 3 0 3 3 4 2 1 3 4 0.66 1 0.69 0 0.36
输出#1
1.68040 1.48440 1.61740
输入解题思路,AI测评打分。不知道怎么写?