#abc257d. D - Jumping Takahashi 2

    ID: 3671 传统题 1000ms 256MiB 尝试: 50 已通过: 11 难度: 7 上传者: 标签>来源atcoder基础算法二分图结构最短路二分答案floyd

D - Jumping Takahashi 2

Score : 400400 points

问题描述

在Takahashi居住的二维平面城镇中,有NN个蹦床。第ii个蹦床位于点(xi,yi)(x_i, y_i)处,具有力量值PiP_i。Takahashi的跳跃能力用SS表示,初始时S=0S=0。每次Takahashi训练时,SS会增加1。

Takahashi可以从第ii个蹦床跳到第jj个蹦床,当且仅当:

  • PiSxixj+yiyjP_iS\geq |x_i - x_j| +|y_i - y_j|

Takahashi的目标是能够选择一个起始蹦床,以便从这个蹦床出发,通过一些跳跃到达任何蹦床。

他至少需要训练多少次才能实现目标?

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There are NN trampolines on a two-dimensional planar town where Takahashi lives. The ii-th trampoline is located at the point (xi,yi)(x_i, y_i) and has a power of PiP_i. Takahashi's jumping ability is denoted by SS. Initially, S=0S=0. Every time Takahashi trains, SS increases by 11.

Takahashi can jump from the ii-th to the jj-th trampoline if and only if:

  • PiSxixj+yiyjP_iS\geq |x_i - x_j| +|y_i - y_j|.

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

  • 2N2002 \leq N \leq 200
  • 109xi,yi109-10^9 \leq x_i,y_i \leq 10^9
  • 1Pi1091 \leq P_i \leq 10^9
  • (xi,yi)(xj,yj) (ij)(x_i, y_i) \neq (x_j,y_j)\ (i\neq j)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

x1x_1 y1y_1 P1P_1

\vdots

xNx_N yNy_N PNP_N

Output

Print the answer.

Sample Input 1

4
-10 0 1
0 0 5
10 0 1
11 0 1

Sample Output 1

2

If he trains twice, S=2S=2, in which case he can reach any trampoline from the 22-nd one.

For example, he can reach the 44-th trampoline as follows.

  • Jump from the 22-nd to the 33-rd trampoline. (Since P2S=10P_2 S = 10 and x2x3+y2y3=10|x_2-x_3| + |y_2-y_3| = 10, it holds that P2Sx2x3+y2y3P_2 S \geq |x_2-x_3| + |y_2-y_3|.)

  • Jump from the 33-rd to the 44-th trampoline. (Since P3S=2P_3 S = 2 and x3x4+y3y4=1|x_3-x_4| + |y_3-y_4| = 1, it holds that P3Sx3x4+y3y4P_3 S \geq |x_3-x_4| + |y_3-y_4|.)

Sample Input 2

7
20 31 1
13 4 3
-10 -15 2
34 26 5
-2 39 4
0 -50 1
5 -20 2

Sample Output 2

18

update @ 2024/3/10 10:55:27