Limits 1s, 256 MB

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 cuvc_{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 nn (2n1032 ≤ n ≤ 10^3), mm (0mmin(105,n(n1))0 ≤ m ≤ min(10^5, n(n-1))), dd (d106d ≤ 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 uu, vv (1u,vn1 ≤ u, v ≤ n) and a positive real number cuvc_{uv} (0<cuv0 < c_{uv}); which corresponds to a trail from spot uu to spot vv with the multiplier cuvc_uv.

cuvc_{uv} and dd 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 uu to vv.


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


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

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.


Login to submit.


33% Solution Ratio
NirjhorEarliest, Jan '20
steinumFastest, 0.1s
steinumLightest, 1.8 MB
steinumShortest, 556B
Toph uses cookies. By continuing you agree to our Cookie Policy.