#P7508. 「Wdsr-2.5」第二次月面战争
「Wdsr-2.5」第二次月面战争
Description
The Human Village can be viewed as a directed graph with nodes and edges, and the Hakurei Shrine is at node . However, due to the time difference, Reimu cannot obtain all residents' positions at once, so she will receive messages in order, and each message contains a node .
- If node originally has no resident, then Reimu learns that there is a resident at node .
- If node originally has a resident, then for some reason, node now has no resident.
For some reason, there may also be residents at node .
After learning each new message, Reimu needs to quickly compute the fastest evacuation time for the residents, in order to make reasonable arrangements (at this time, you may assume there are no residents on other nodes). To avoid congestion and other unpredictable difficulties, Reimu sets the following rules:
- At each moment, each resident can move one step along one directed edge, or stay where they are.
- At each moment, at each node, there can be at most one resident.
- When a resident arrives at the Hakurei Shrine, then in the next moment they can enter the barrier to receive shelter. You may assume that after a resident enters the barrier, their journey ends.
The fastest evacuation time refers to the minimum time needed for all residents to enter the barrier.
Input Format
The first line contains four positive integers , with meanings as described above.
The next lines each contain two positive integers , describing a directed edge . Self-loops or multiple edges may appear; please ignore them by yourself.
The next line contains integers , meaning that in the -th message, the resident status of node changes.
Output Format
Output lines in total. The -th line represents the minimum evacuation time to evacuate all residents after applying the first messages.
7 7 4 1
2 1
3 1
4 2
5 2
6 1
7 6
3 2
7 1 2 3
3
3
3
4
Hint
Explanation for Sample 1

This figure shows the initial state, the first operation, and the second operation. We can see that:
- After the first operation, node reaches the shrine fastest via , and then spends unit of time to enter the shrine, for a total time of units.
- After the second operation, node spends moment to enter the shrine, and node still reaches the shrine via , then spends unit of time to enter the shrine. The total time is units.

This figure shows the situation after the third operation.
At the first moment, enters the shrine, ; at the second moment, enters the shrine, ; at the third moment, everyone has entered the shrine, so the total time is units.

This figure shows the situation after the fourth operation.
At the first moment, enters the shrine, , and does not move; at the second moment, enters the shrine, , and does not move. Then it takes more moments for everyone to enter the shrine, so the total time is units.
Samples 2 and 3
See the attached files provided.
Constraints and Notes
$$\def\bd{\boldsymbol} \def\a{\texttt{A}} % 链的性质 \def\b{\texttt{B}} % 菊花图的性质 \def\p{\texttt{P}} % k为正的性质 \def\n{\text{无特殊限制}} \def\l{\hline} \def\arraystretch{1.5}\begin{array}{|c|c|c|c|c|}\l \textbf{数据点} & \bd{n} & \bd{m} & \bd{k} & \textbf{特殊性质} \cr\l 1\sim4 & n\le 8 & m\le 10 & k\le 10 & - \cr\l 5,6 & \n & m=n-1 & \n & \p,\a \cr\l 7,8 & \n & m=n-1 & \n & \p,\b \cr\l 9 & n\le 10^5 & m=n-1 & k\le 10^5 & \p \cr\l 10\sim 12 & n\le 10^3 & m\le 10^3 & k\le 10^3 & - \cr\l 13,14 & n\le 10^5 & m\le 10^5 & k\le 10^5 & \p \cr\l 15\sim 17 & n\le 10^5 & m\le 10^5 & k\le 10^5 & - \cr\l 18\sim 20 & \n & \n & \n & - \cr\l \end{array}$$- Special property : It is guaranteed that there are only operations that make residents appear.
- Special property : It is guaranteed that the whole graph is a chain, but it is not guaranteed that is an endpoint of the chain.
- Special property : It is guaranteed that all nodes except point to .
For all testdata, it holds that $1\le n\le 10^6; 1\le m\le 1.05\times 10^6; 1\le k\le 10^6$. It is guaranteed that all nodes can reach .
Translated by ChatGPT 5
京公网安备 11011102002149号