#P7871. 「Wdoi-4」芙兰?姆Q!贤者与谜题
「Wdoi-4」芙兰?姆Q!贤者与谜题
Background
The background does not contain key information for solving the problem and can be skipped.
Flandre Scarlet is a vampire who once lived in the basement of the Scarlet Devil Mansion. Unlike other vampires, Flandre has special wings made of colorful crystals, different from the bat-like wings of other vampires: crystals of different colors are lined up in order.
The colors of the crystals on Flandre's wings from inner to outer are sky blue, blue, purple, pink, orange, yellow, light green, and sky blue. Therefore, in fact, Flandre's wings are very likely composed of Patchouli's "Philosopher's Stone".
But Flandre does not care about that. She only cares about the energy flow between the Philosopher's Stones arranged in the shape of wings: if a Philosopher's Stone is given energy, it will enter an excited state. An excited Philosopher's Stone is very unstable: the burst of its huge energy will affect surrounding Philosopher's Stones, causing energy transfer.
Flandre finds this very interesting, and made a riddle to test Patchouli. But as a sage, Patchouli does not want to think and just wants to slack off, so the task is handed to you!
Problem Description
Flandre got Philosopher's Stones from Patchouli and lined them up from left to right in a row. Patchouli can assign each Philosopher's Stone an energy level, which determines how energy is transferred between stones. Note that each energy level must be a positive integer, and no two Philosopher's Stones may have the same energy level.
If the -th Philosopher's Stone is energized (enters the excited state), it will pass energy to the one with the smaller energy level among the -th and -th stones. In particular, if a stone has only one neighbor, it will only send energy to that neighbor. Note that even if the -th stone's energy level is lower than both the -th and -th stones, it can still transmit energy.
Now Flandre has conditions: each condition gives two positive integers , meaning that if Flandre activates the energy of the -th Philosopher's Stone, then the energy will eventually pass through the -th stone.
However, since Patchouli has asthma, setting the energy levels is very tiring. Therefore, if there exists a legal assignment of energy levels, please find the lexicographically smallest one. For two assignments , we say is lexicographically smaller than if and only if there exists a such that we have , and .
If a legal assignment exists, output the lexicographically smallest one; otherwise output QED.
Input Format
The first line contains two integers , representing the number of Philosopher's Stones and the number of Flandre's conditions.
The next lines each contain two integers , describing one condition.
Output Format
If no legal assignment exists, output QED. Otherwise output integers, representing the lexicographically smallest assignment.
10 4
1 2
3 7
8 10
5 6
1 4 8 3 7 2 6 10 5 9
Hint
Input/output sample can be found in the attached files .
Input/output sample can be found in the attached files .
Constraints and Notes
For of the testdata, , , .
$$\def\arraystretch{1.5} \begin{array}{|c|c|c|c|} \hline \textbf{Test Point} & \bm{n\le} & \bm{q\le} & \textbf{Special Constraint} \cr \hline 1\sim 3 & 7 & 7 & - \cr \hline 4\sim6 & 100 & 100 & - \cr \hline 7 & 10^5 & 1 & -\cr \hline 8\sim 10 & 3\times 10^5 & 3\times 10^5 & s_i\le t_i \cr \hline 11\sim 12 & 10^5 & 10 & - \cr \hline 13\sim 20 & 3\times 10^5 & 3\times 10^5 & -\cr \hline \end{array}$$Translated by ChatGPT 5