#P7508. 「Wdsr-2.5」第二次月面战争

    ID: 6446 远端评测题 1500ms 128MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>贪心2021洛谷原创O2优化图遍历

「Wdsr-2.5」第二次月面战争

Description

The Human Village can be viewed as a directed graph with nn nodes and mm edges, and the Hakurei Shrine is at node tt. However, due to the time difference, Reimu cannot obtain all residents' positions at once, so she will receive kk messages in order, and each message contains a node xx.

  • If node xx originally has no resident, then Reimu learns that there is a resident at node xx.
  • If node xx originally has a resident, then for some reason, node xx now has no resident.

For some reason, there may also be residents at node tt.

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 n,m,k,tn, m, k, t, with meanings as described above.

The next mm lines each contain two positive integers u,vu, v, describing a directed edge uvu\to v. Self-loops or multiple edges may appear; please ignore them by yourself.

The next line contains kk integers xix_i, meaning that in the ii-th message, the resident status of node xix_i changes.

Output Format

Output kk lines in total. The ii-th line represents the minimum evacuation time to evacuate all residents after applying the first ii 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

main1.png

This figure shows the initial state, the first operation, and the second operation. We can see that:

  • After the first operation, node 77 reaches the shrine fastest via 7617\to 6\to 1, and then spends 11 unit of time to enter the shrine, for a total time of 33 units.
  • After the second operation, node 11 spends 11 moment to enter the shrine, and node 77 still reaches the shrine via 7617\to 6\to 1, then spends 11 unit of time to enter the shrine. The total time is 33 units.

main2.png

This figure shows the situation after the third operation.

At the first moment, 11 enters the shrine, 21,762\to 1, 7\to 6; at the second moment, 11 enters the shrine, 616\to 1; at the third moment, everyone has entered the shrine, so the total time is 33 units.

main3.png

This figure shows the situation after the fourth operation.

At the first moment, 11 enters the shrine, 31,763\to 1, 7\to 6, and 22 does not move; at the second moment, 11 enters the shrine, 212\to 1, and 66 does not move. Then it takes 22 more moments for everyone to enter the shrine, so the total time is 44 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 P\texttt{P}: It is guaranteed that there are only operations that make residents appear.
  • Special property A\texttt{A}: It is guaranteed that the whole graph is a chain, but it is not guaranteed that tt is an endpoint of the chain.
  • Special property B\texttt{B}: It is guaranteed that all nodes except tt point to tt.

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 tt.

Translated by ChatGPT 5