No.466 Diorama
Problem Statement
One day, Iroha-chan was telling Meguru-chan about her hometown.
In Iroha-chan's hometown, several villages were connected by several directed waterways.
The villages were numbered 0, 1, 2, ... in order. Among them, village 0 and village 1 were special villages that served as water sources.
When water is released from village 0 or village 1, it reaches every village reachable by following the waterways in their directions.
A single waterway never goes from a village $x$ to the same village $x$, but water may return to its original village by passing through several waterways.
Also, water may flow into village 0 or village 1 from other villages.
According to Iroha-chan, her hometown satisfied all of the following conditions.
- The hometown had 2 or more villages.
- Every village received water from village 0 or village 1.
- When water was released from village 0, it reached $A$ villages, including village 0.
- When water was released from village 1, it reached $B$ villages, including village 1.
- The number of villages that received water from both village 0 and village 1 was $C$. (Here, $C \leq \min(A, B)$ holds.)
- There were at most $D$ waterways.
To build the diorama, she needs a combination of "the number of villages, the number of waterways, and the connections of the waterways (from which village to which village each waterway runs)" that satisfies all the conditions Iroha-chan described.
On behalf of Meguru-chan, find one such combination.
Iroha-chan may be misremembering, so no combination satisfying the conditions may exist; in that case, quietly let her know.
Input
$A$ $B$ $C$ $D$
The input consists of one line, in which the values $A, B, C, D$ from the statement are given separated by spaces.
$A, B, C, D$ satisfy the following conditions.
- $A, B, C, D$ are integers
- $1 \leq A \leq 10^4$
- $1 \leq B \leq 10^4$
- $0 \leq C \leq \min(A, B)$
- $0 \leq D \leq 10^5$
Output
Output as follows.
- If no combination satisfying the problem's conditions exists, print -1, followed by a newline.
In this case, the output is only one line. - Otherwise, the output is as follows.
$N$ $M$ $a_1$ $b_1$ $a_2$ $b_2$ $\dots$ $a_M$ $b_M$
- On the first line, print the number of villages $N$ and the number of waterways $M$.
- On each of lines 2 through $M + 1$, when a waterway exists in the direction from village $a_i$ to village $b_i$, print $a_i$ and $b_i$ separated by a space.
- However, you must not print the same waterway more than once. Also, $0 \leq a_i, b_i < N, a_i \neq b_i$ must be satisfied.
- Furthermore, all output values must fit in a signed 64-bit integer type, and the entire output must fit within 20MB.
- Print a newline at the end.
Sample
Sample 1
Input
6 4 2 12
Output
8 10 0 2 0 4 1 2 1 7 2 3 4 2 4 3 4 5 4 6 7 3
This solution is only one example; other solutions satisfying the conditions also exist.
Sample 2
Input
5 3 3 5
Output
5 4 0 1 0 2 1 3 1 4
Water may reach village 1 from village 0, or village 0 from village 1.
Sample 3
Input
1 4 0 3
Output
5 3 1 2 1 3 1 4
Sample 4
Input
9 8 5 10
Output
-1
It seems there are too few waterways.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
🍡yurahuna