#abc368e. E - Train Delay

E - Train Delay

Score : 475475 points

问题陈述

在Atcoder国,有NN个城市,编号从11NN,以及MM列火车,编号从11MM。第ii列火车从城市AiA_i出发,出发时间为SiS_i,到达城市BiB_i,到达时间为TiT_i

给定一个正整数X1X_1,找到一种方法来设置非负整数X2,,XMX_2,\ldots,X_M,使得满足以下条件的X2++XMX_2+\ldots+X_M的值尽可能小。

  • 条件:对于所有满足1i,jM1 \leq i,j \leq M的对(i,j)(i,j),如果Bi=AjB_i=A_jTiSjT_i \leq S_j,则Ti+XiSj+XjT_i+X_i \leq S_j+X_j
    • 换句话说,对于任何一对原本可以换乘的火车,即使在延迟了每列火车ii的出发和到达时间XiX_i之后,仍然可以换乘。

可以证明,设置X2,,XMX_2,\ldots,X_M的方法,使得X2++XMX_2+\ldots+X_M的值尽可能小是唯一的。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

In the nation of Atcoder, there are NN cities numbered 11 to NN, and MM trains numbered 11 to MM. Train ii departs from city AiA_i at time SiS_i and arrives at city BiB_i at time TiT_i.

Given a positive integer X1X_1, find a way to set non-negative integers X2,,XMX_2,\ldots,X_M that satisfies the following condition with the minimum possible value of X2++XMX_2+\ldots+X_M.

  • Condition: For all pairs (i,j)(i,j) satisfying 1i,jM1 \leq i,j \leq M, if Bi=AjB_i=A_j and TiSjT_i \leq S_j, then Ti+XiSj+XjT_i+X_i \leq S_j+X_j.
    • In other words, for any pair of trains that are originally possible to transfer between, it is still possible to transfer even after delaying the departure and arrival times of each train ii by XiX_i.

It can be proved that such a way to set X2,,XMX_2,\ldots,X_M with the minimum possible value of X2++XMX_2+\ldots+X_M is unique.

Constraints

  • 2N2×1052 \leq N \leq 2\times 10^5
  • 2M2×1052 \leq M \leq 2\times 10^5
  • 1Ai,BiN1 \leq A_i,B_i \leq N
  • AiBiA_i \neq B_i
  • 0Si<Ti1090 \leq S_i < T_i \leq 10^9
  • 1X11091 \leq X_1 \leq 10^9
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN MM X1X_1

A1A_1 B1B_1 S1S_1 T1T_1

\vdots

AMA_M BMB_M SMS_M TMT_M

Output

Print X2,,XMX_2,\ldots,X_M that satisfy the condition with the minimum possible sum, in that order, separated by spaces.

Sample Input 1

3 6 15
1 2 10 20
1 2 20 30
2 3 25 40
2 3 35 50
3 1 15 30
3 1 45 60

Sample Output 1

0 10 0 0 5

The arrival of train 11 from city 11 to 22 is delayed by 1515 and becomes time 3535.
To allow transfer from train 11 to 33 in city 22, the departure of train 33 is delayed by 1010, making it depart at time 3535 and arrive at time 5050.
Further, to allow transfer from train 33 to 66 in city 33, the departure of train 66 is delayed by 55, making it depart at time 5050.
Other trains can operate without delay while still allowing transfers between originally transferable trains, so (X2,X3,X4,X5,X6)=(0,10,0,0,5)(X_2,X_3,X_4,X_5,X_6)=(0,10,0,0,5) satisfies the condition.
Moreover, there is no solution with a smaller sum that satisfies the condition, so this is the answer.

Sample Input 2

10 9 100
1 10 0 1
10 2 1 100
10 3 1 100
10 4 1 100
10 5 1 100
10 6 1 100
10 7 1 100
10 8 1 100
10 9 1 100

Sample Output 2

100 100 100 100 100 100 100 100

Sample Input 3

4 4 10
1 2 0 1
1 2 0 10
2 3 100 200
2 4 100 200

Sample Output 3

0 0 0