#abc373d. D - Hidden Weights(waiting SPJ)
D - Hidden Weights(waiting SPJ)
Score : points
问题陈述
给定一个有向图,包含 个顶点和 条边。第 条有向边从顶点 指向顶点 ,并且有权重 。
找到一种方法,为每个顶点写上一个介于 和 之间的整数,以满足以下条件。
- 设 为写在顶点 上的值。对于所有边 ,满足 。
保证对于给定的输入至少存在一种这样的分配。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
You are given a directed graph with vertices and edges. The -th directed edge goes from vertex to vertex and has a weight of .
Find one way to write an integer between and , inclusive, to each vertex such that the following condition is satisfied.
- Let be the value written on vertex . For all edges , it holds that .
It is guaranteed that at least one such assignment exists for the given input.
Constraints
- If , then and
- All input values are integers.
- There exists at least one assignment satisfying the conditions.
Input
The input is given from Standard Input in the following format:
Output
Let be the integer written on vertex . Print in this order, separated by spaces, on a single line. If there are multiple solutions, you may print any of them.
Sample Input 1
3 3
1 2 2
3 2 3
1 3 -1
Sample Output 1
3 5 2
By setting , we have , , , satisfying the conditions.
For example, is also a valid answer.
Sample Input 2
4 2
2 1 5
3 4 -3
Sample Output 2
5 0 6 3
For example, and are also valid answers.
Sample Input 3
5 7
2 1 18169343
3 1 307110901
4 1 130955934
2 3 -288941558
2 5 96267410
5 3 -385208968
4 3 -176154967
Sample Output 3
200401298 182231955 -106709603 69445364 278499365