No.2916 Minimizing Progressive Cost
Note
The execution time limit for this problem is 3500[ms].
Problem Statement
At the beginning of the input, an integer $N$ of at least $2$ and $2$ positive integers $M,C$ are given.
A country has $N$ islands and $M$ bridges connecting them. The only means of travel in this country is crossing bridges, and there is at most $1$ bridge connecting any $2$ islands.
The islands are numbered with the positive integers $i$ not exceeding $N$ and are called island $i$, and the bridges are numbered with the positive integers $m$ not exceeding $M$ and are called bridge $m$.
For each positive integer $m$ not exceeding $M$:
- Bridge $m$ connects island $i_m$ and island $j_m$ ($i_m$ and $j_m$ are integers satisfying $1 \leq i_m < j_m \leq N$).
- When crossing bridge $m$, a person whose current money is $c$ must pay a toll of $\lfloor \frac{c}{r_m} \rfloor + w_m$ ($r_m$ and $w_m$ are positive integers independent of $c$), and cannot pay a toll greater than the money they have.
For each positive integer $c$ not exceeding $C$, determine whether a person on island $1$ with money $c$ can travel to island $N$, and if possible, find the maximum amount of money they can have after arriving at island $N$.
Input
The input is given from standard input in $1 + M$ lines in the following format:
- Line $1$ contains $N, M, C$ separated by single spaces.
- For each positive integer $m$ not exceeding $M$, line $2 + m$ contains $i_m,j_m,r_m,w_m$ separated by single spaces.
$N$ $M$ $C$ $i_1$ $j_1$ $r_1$ $w_1$ $\vdots$ $i_M$ $j_M$ $r_M$ $w_M$
Constraints
The input satisfies the following constraints:
- $N$ is an integer satisfying $2 \leq N \leq 10$.
- $M$ is an integer satisfying $1 \leq M \leq \frac{N(N-1)}{2}$.
- $C$ is an integer satisfying $1 \leq C \leq 10^5$.
- For any positive integer $m$ not exceeding $M$:
- $i_m$ and $j_m$ are integers satisfying $1 \leq i_m < j_m \leq N$.
- $r_m$ is an integer satisfying $1 \leq r_m \leq C$.
- $w_m$ is an integer satisfying $1 \leq w_m \leq C$.
- For any positive integers $m_0,m_1$ not exceeding $M$, if $m_0 \neq m_1$ then $(i_{m_0},j_{m_0}) \neq (i_{m_1},j_{m_1})$.
Output
For each positive integer $c$ not exceeding $C$, output on line $c$ the maximum amount of money after arriving at island $N$ if a person on island $1$ with money $c$ can travel to island $N$, and -1 otherwise.
Print a newline at the end.
Sample
Sample 1
Input
2 1 1 1 2 1 1
Output
-1
Let $c$ be the initial money. Since $1 \leq c \leq C = 1$, we have $c = 1$.
To travel from island $1$ to island $N = 2$, one must cross bridge $1$, which connects island $1$ and island $2$. Crossing bridge $1$ requires paying a toll of $\lfloor \frac{c}{1} \rfloor + 1 = 2$, which is greater than $c$, so it cannot be paid.
Sample 2
Input
2 1 3 1 2 2 1
Output
0 0 1
Let $c$ be the initial money. We have $1 \leq c \leq C = 3$.
To travel from island $1$ to island $N = 2$, one can cross bridge $1$, which connects island $1$ and island $2$. Crossing bridge $1$ requires paying a toll of $\lfloor \frac{c}{2} \rfloor + 1$.
When $c = 1$, $\lfloor \frac{c}{2} \rfloor + 1 = 1$, so bridge $1$ can be crossed, and the money upon arriving at island $2$ is $c - 1 = 0$. It is not possible to arrive at island $2$ with more money than this.
When $c = 2$, $\lfloor \frac{c}{2} \rfloor + 1 = 2$, so bridge $1$ can be crossed, and the money upon arriving at island $2$ is $c - 2 = 0$. It is not possible to arrive at island $2$ with more money than this.
When $c = 3$, $\lfloor \frac{c}{2} \rfloor + 1 = 2$, so bridge $1$ can be crossed, and the money upon arriving at island $2$ is $c - 2 = 1$. It is not possible to arrive at island $2$ with more money than this.
Sample 3
Input
4 4 5 1 2 3 2 1 3 2 1 2 4 3 1 3 4 2 1
Output
-1 -1 0 0 1
Let $c$ be the initial money. We have $1 \leq c \leq C = 6$.
To travel from island $1$ to island $N = 4$, one can either cross bridge $1$, which connects island $1$ and island $2$, and then bridge $3$, which connects island $2$ and island $4$, or cross bridge $2$, which connects island $1$ and island $3$, and then bridge $4$, which connects island $3$ and island $4$. On the former route, crossing bridge $1$ requires paying a toll of $\lfloor \frac{c}{3} \rfloor + 2$, and, letting $c'$ be the remaining amount, crossing bridge $3$ requires paying a further toll of $\lfloor \frac{c'}{3} \rfloor + 1$. On the latter route, crossing bridge $2$ requires paying a toll of $\lfloor \frac{c}{3} \rfloor + 1$, and, letting $c'$ be the remaining amount, crossing bridge $4$ requires paying a further toll of $\lfloor \frac{c'}{2} \rfloor + 1$.
When $c = 1$, on the former route, $\lfloor \frac{c}{3} \rfloor + 2 = 2 > c$, so bridge $1$ cannot be crossed. On the latter route, $\lfloor \frac{c}{2} \rfloor + 1 = 1 = c$, so bridge $2$ can be crossed, but the money upon arriving at island $3$ is $c' = c - 1 = 0$, and $\lfloor \frac{c'}{2} \rfloor + 1 = 1 > c'$, so bridge $4$ cannot be crossed. Island $4$ cannot be reached by either route.
When $c = 2$, on the former route, $\lfloor \frac{c}{3} \rfloor + 2 = 2 = c$, so bridge $1$ can be crossed, but the money upon arriving at island $2$ is $c' = c - 2 = 0$, and $\lfloor \frac{c'}{3} \rfloor + 1 = 1 > c'$, so bridge $3$ cannot be crossed. On the latter route, $\lfloor \frac{c}{2} \rfloor + 1 = 2 = c$, so bridge $2$ can be crossed, but the money upon arriving at island $3$ is $c' = c - 2 = 0$, and $\lfloor \frac{c'}{2} \rfloor + 1 = 1 > c'$, so bridge $4$ cannot be crossed. Island $4$ cannot be reached by either route.
When $c = 3$, on the former route, $\lfloor \frac{c}{3} \rfloor + 2 = 3$, so bridge $1$ can be crossed, and the money upon arriving at island $2$ is $c' = c - 3 = 0$, and $\lfloor \frac{c'}{3} \rfloor + 1 = 1 > c'$, so bridge $3$ cannot be crossed. On the latter route, $\lfloor \frac{c}{2} \rfloor + 1 = 2 < c$, so bridge $2$ can be crossed, and the money upon arriving at island $3$ is $c' = c - 2 = 1$, and $\lfloor \frac{c'}{2} \rfloor + 1 = 1 = c'$, so bridge $4$ can be crossed, and the money upon arriving at island $4$ is $c' - 1 = 0$. It is not possible to arrive at island $4$ with more money than this.
When $c = 4$, on the former route, $\lfloor \frac{c}{3} \rfloor + 2 = 3 < c$, so bridge $1$ can be crossed, and the money upon arriving at island $2$ is $c' = c - 3 = 1$, and $\lfloor \frac{c'}{3} \rfloor + 1 = 1 = c'$, so bridge $3$ can be crossed, and the money upon arriving at island $4$ is $c' - 1 = 0$. On the latter route, $\lfloor \frac{c}{2} \rfloor + 1 = 3 < c$, so bridge $2$ can be crossed, and the money upon arriving at island $3$ is $c' = c - 3 = 1$, and $\lfloor \frac{c'}{2} \rfloor + 1 = 1 = c'$, so bridge $3$ can be crossed, and the money upon arriving at island $4$ is $c' - 1 = 0$. Therefore, the amount of money remaining is the same on the former and latter routes. It is not possible to arrive at island $4$ with more money than this.
When $c = 5$, on the former route, $\lfloor \frac{c}{3} \rfloor + 1 = 3 < c$, so bridge $1$ can be crossed, and the money upon arriving at island $2$ is $c' = c - 3 = 2$, and $\lfloor \frac{c'}{3} \rfloor + 1 = 1 < c'$, so bridge $3$ can be crossed, and the money upon arriving at island $4$ is $c' - 1 = 1$. On the latter route, $\lfloor \frac{c}{2} \rfloor + 1 = 3 < c$, so bridge $2$ can be crossed, and the money upon arriving at island $3$ is $c' = c - 3 = 2$, and $\lfloor \frac{c'}{2} \rfloor + 1 = 2 = c'$, so bridge $3$ can be crossed, and the money upon arriving at island $4$ is $c' - 2 = 0$. Therefore, more money can be kept on the former route. It is not possible to arrive at island $4$ with more money than this.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。