#P7831. [CCO 2021] Travelling Merchant

    ID: 8906 远端评测题 1000ms 128MiB 尝试: 20 已通过: 9 难度: 8 上传者: 标签>图论贪心2021CCO(加拿大)拓扑排序

[CCO 2021] Travelling Merchant

Problem Description

A country has nn cities and mm directed roads, and a travelling merchant travels among these cities.

The ii-th road goes from city aia_i to city bib_i. He can use this road only when his assets are at least rir_i yuan. After taking this road, his assets increase by pip_i yuan.

He wants to be able to keep travelling forever without stopping, so he wants to know, starting from each city, the minimum initial assets required.

Input Format

The first line contains two integers n,mn, m.

The next mm lines each contain four integers ai,bi,ri,pia_i, b_i, r_i, p_i on the ii-th line.

Output Format

Output one line with nn integers. If the answer for the ii-th city does not exist, then the ii-th integer is 1-1. Otherwise, it is the minimum initial assets required (in yuan).

5 5
3 1 4 0
2 1 3 0
1 3 1 1
3 2 3 1
4 2 0 2
2 3 3 1 -1

Hint

Sample #1 Explanation

Take city 22 as an example: starting from city 22 with initial assets of 33 yuan, he can loop forever among cities 2,1,32, 1, 3.

Constraints

For 27\frac{2}{7} of the testdata, 2n,m2×1032 \leq n, m \leq 2 \times 10^3.

For another 1549\frac{15}{49} of the testdata, pi=0p_i = 0.

For 100%100\% of the testdata, 2n,m2×1052 \leq n, m \leq 2 \times 10^5, 1ai,bin1 \leq a_i, b_i \leq n, aibia_i \neq b_i, 0ri,pi1090 \leq r_i, p_i \leq 10^9, it is guaranteed that there are no self-loops but there may be multiple edges.

Source

CCO2021 D2T1

Translated by ChatGPT 5