atcoder#ABC257D. [ABC257D] Jumping Takahashi 2
[ABC257D] Jumping Takahashi 2
Score : points
Problem Statement
There are trampolines on a two-dimensional planar town where Takahashi lives. The -th trampoline is located at the point and has a power of . Takahashi's jumping ability is denoted by . Initially, . Every time Takahashi trains, increases by .
Takahashi can jump from the -th to the -th trampoline if and only if:
- .
Takahashi's objective is to become able to choose a starting trampoline such that he can reach any trampoline from the chosen one with some jumps.
At least how many times does he need to train to achieve his objective?
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
4
-10 0 1
0 0 5
10 0 1
11 0 1
2
If he trains twice, , in which case he can reach any trampoline from the -nd one.
For example, he can reach the -th trampoline as follows.
- Jump from the -nd to the -rd trampoline. (Since and , it holds that .)
- Jump from the -rd to the -th trampoline. (Since and , it holds that .)
7
20 31 1
13 4 3
-10 -15 2
34 26 5
-2 39 4
0 -50 1
5 -20 2
18