407293: GYM102756 H Voyager

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

H. Voyagertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Armed with a small canoe and a mental map of the stars, Kiana embarks upon a voyage to a distant island from her own, where she suspects she may find valuable resources that can be brought back to her village community. Unfortunately, the seas can be unforgiving, and Kiana knows that her feeble canoe may not be sturdy enough to survive the extent of the voyage. However, Kiana's island lies within the Polynesian Triangle, and there are hundreds of other islands nearby, $$$N$$$ to be precise, where Kiana should be able to find more boat-building wood and construct a hardier vessel. Each island, located at $$$(x_i, y_i)$$$ miles in the Pacific Ocean, contains $$$s_i$$$ "units" of boat-building supplies, whereby each supply unit allows Kiana to upgrade her boat to be capable of traveling 1 additional mile of distance at one time without sinking.

For example, Kiana starts at the $$$0^{th}$$$ island with $$$s_0$$$ supplies that she has already used to build her canoe, and until she upgrades her boat, she can travel a maximum of $$$s_0$$$ continuous miles in any direction before her canoe fails. If the distance between say the $$$0^{th}$$$ and $$$1^{st}$$$ island is less than $$$s_0$$$, then Kiana could sail to the $$$1^{st}$$$ island and upgrade her boat with $$$s_1$$$ supply units, so that going forward she could sail to any island within $$$s_0 + s_1$$$ of her current position.

Given the locations of the Polynesian islands and the amount of wood supplies at each island, determine whether or not Kiana can make it to her destination.

Input

The first line of input contains the integer $$$N$$$ ($$$2 \leq N < 10^3$$$), denoting the number of neighboring islands known to Kiana. The next $$$N$$$ lines each contain three integers, $$$x_i$$$, $$$y_i$$$, and $$$s_i$$$ ($$$0 \leq x_i, y_i, s_i < 10^6$$$), where $$$(x_i, y_i)$$$ is the location of the $$$i^{th}$$$ Polynesian island and $$$s_i$$$ is the number of wood supply units available at the island for Kiana to harvest for canoe improvements. The $$$0^{th}$$$ island, described in the first line of input, is Kiana's starting location, and the last line of input, for the $$$N-1^{th}$$$ island, describes Kiana's target destination.

Output

Output "YES" if it is possible for Kiana to reach her destination and "NO" otherwise.

ExampleInput
7
50 50 3
50 52 0
50 55 0
50 58 10
50 49 1
50 35 10
74 50 0
Output
YES

加入题单

算法标签: