Hidden Weights
You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.
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
SDNU_ACM_ICPC_2024_WEEKLY_PRACTICE_1st
- Status
- Done
- Rule
- ACM/ICPC
- Problem
- 8
- Start at
- 2024-10-27 18:30
- End at
- 2024-10-27 21:30
- Duration
- 3 hour(s)
- Host
- Partic.
- 39