QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#15259. Probability Charger

Statistics

The famous electronics brand SHOI has just released its next-generation electronic product, the "Probabilistic Charger":

"Using brand-new nano-scale processing technology, whether components and wires can conduct electricity is determined entirely by true random numbers! The SHOI Probabilistic Charger, an indispensable necessity for your life! Can it charge? Try it out now!"

The SHOI Probabilistic Charger consists of $n$ charging components connected by $n-1$ wires. When charging, whether each wire conducts electricity is determined by a probability, and whether each charging component itself charges directly is also determined by a probability. Subsequently, electrical energy can flow from components that are directly charged through conducting wires to allow other components to be charged indirectly.

As a loyal customer of the SHOI company, you cannot suppress the urge to buy SHOI products. After waiting in a long line for a week, you finally got your hands on the latest model of the SHOI Probabilistic Charger. You can't wait to plug the SHOI Probabilistic Charger into a power source—and suddenly you wonder, what is the expected number of components that will enter a charged state?

Input

The first line contains an integer $n$, the number of charging components in the probabilistic charger. The charging components are numbered from $1$ to $n$.

The following $n-1$ lines each contain three integers $a, b, p$, describing a wire connecting components $a$ and $b$, with a conduction probability of $p\%$.

The $(n+2)$-th line contains $n$ integers $q_i$, representing the probability that component $i$ is directly charged as $q_i\%$.

Output

Output a single real number representing the expected number of components that enter a charged state, rounded to 6 decimal places.

Examples

Input 1

3
1 2 50
1 3 50
50 0 0

Output 1

1.000000

Input 2

5
1 2 90
1 3 80
1 4 70
1 5 60
100 10 20 30 40

Output 2

4.300000

Constraints

For $30\%$ of the data, $n \le 5000$.

For $100\%$ of the data, $n \le 500000$, $0 \le p, q_i \le 100$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.