You are given a directed acyclic graph, with each edge $$$i$$$ having a weight in the range $$$[l_i, r_i]$$$. Assign weights to each edge such that all paths from $$$1$$$ to $$$n$$$ have the same cost. It is guaranteed that node $$$1$$$ is the only source$$$^{\text{∗}}$$$ and node $$$n$$$ is the only sink$$$^{\text{†}}$$$.
$$$^{\text{∗}}$$$A source node has no incoming edges, and has outgoing edges.
$$$^{\text{†}}$$$A sink node has no outgoing edges, and has incoming edges.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \leq t \leq 10^{2}$$$). The description of the test cases follows.
The first line of each test case contains integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$n - 1 \leq m \leq \min(4 \cdot 10^{3}, \frac{n(n-1)}{2})$$$) — the number of nodes and edges in the graph.
The next $$$m$$$ lines contain two integers $$$u_i$$$, $$$v_i$$$, $$$l_i$$$, and $$$r_i$$$ ($$$1 \leq u_i, v_i \leq n$$$, $$$u_i \neq v_i$$$, $$$1 \leq l_i \leq r_i \leq 10^{9}$$$) — the edge endpoints, and the range bounding the edge weight. It is guaranteed that there are no multiedges.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^3$$$, and the sum of $$$m$$$ over all test cases does not exceed $$$2 \cdot 10^{3}$$$.
—
Tests in subtasks are numbered from $$$1−20$$$ with samples skipped. Each test is worth $$$\frac{100}{20}=5$$$ points.
Tests $$$1-4$$$ satisfies $$$l_i = 1$$$ and $$$r_i = 10^9$$$.
Tests $$$5-20$$$ satisfy no additional constraints.
If no valid construction exists, print $$$-1$$$. Otherwise, print the edge weights, in order of input.
24 41 2 1 101 3 1 102 4 1 103 4 1 104 41 2 5 51 3 10 102 4 1 13 4 1 1
10 10 10 10-1
For the first test case, assigning all the edge weights to $$$10$$$ ensures that all paths from $$$1$$$ to $$$n$$$ have the same cost.
For the second test case, we can show that any weight assignment results in paths from $$$1$$$ to $$$n$$$ with differing weights.
—
Problem Idea: dutin
Problem Preparation: eysbutno
Occurrences: Advanced J