# Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Ada is wondering in her dreamland. Her dreamland consists of n spots. She has this weird machine with her that shows real numbers. And whenever she goes from spot u to v, if she can (by following a trail), the value shown in the machine gets multiplied with c_{uv} which is another weird value for each trail that exists between two spots.

Ada is currently in spot 1 and her machine currently reads value d. She wants to go to spot n in a way so that the machine shows zero when she reaches n. Is that possible?

Please note that, Ada can visit a spot multiple times if it helps her.

Ada’s machine displays zero when the value is either zero or tends to be zero. To say that x tends to zero is to say that x varies in such a way that its numerical value becomes and remains less than any positive number that we may choose, no matter how small.

First line contains two integers and one positive real number **n** (2 ≤ n ≤ 10^{3}), **m** (0 ≤ m ≤ min(10^5, n(n-1))), **d** (d ≤ 10^{6}); the number of spots, the number of trails, the initial reading of the machine respectively.

Each of the next m lines contains two integers **u**, **v** (1 ≤ u, v ≤ n) and a positive real number **c _{uv}** (0 < c

c_{uv} and d will have exactly 2 digits after the decimal place.

Note that the trails are unidirectional. Also, there will be no trail from a spot to itself. And there exists at most one trail from a spot u to v.

If Ada can not reach spot n anyhow, please output “Unreachable” on a line. Else, print “Yes” if she can obtain zero at the machine reading after arriving in spot n. Print “No” otherwise.

Input | Output |
---|---|

5 5 1.00 1 2 0.10 2 3 7.00 2 4 2.00 4 3 0.90 3 5 0.05 | No |

There are two ways to go to 5 from 1: A. 1-2-3-5 yields a value of 1 × 0.10 × 7.00 × 0.05 = 0.035. B. 1-2-4-3-5 yields a value of 1 × 0.10 × 2.00 × 0.90 × 0.05 = 0.09. None of them yields 0. |

25% Solution Ratio

NirjhorEarliest,

EgorKulikovFastest, 0.2s

NirjhorLightest, 4.1 MB

tmwilliamlin168Shortest, 1142B

Login to submit

You are given a graph and asked if there is any node u such that: u is part of a cycle where the m...