JOI Open Contest
The JOI Co., Ltd. has
Each server has a high-performance synchronization system. When two servers can exchange pieces of information each other and they contain different pieces of information, they automatically synchronize the pieces of information. After a synchronization between the server A and the server B, both of the servers A and B will contain all the pieces of information which are contained in at least one of the servers A and B before the synchronization.
In order to reduce the cost, only
In the beginning (at time 0), no lines are built. Sometimes, lines are built in a harsh condition (e.g. in a desert, in the bottom of sea). Some of the lines become unavailable at some point. Once a line becomes unavailable, it is not possible to use it until it is rebuilt.
It is known that, at time
We need to know the number of different pieces of information contained in some of the servers at time
Task
Write a program which, given information of the lines to be built and the state of the lines, determine the number of different pieces of information contained in some of the servers.
Input Specification
Read the following data from the standard input.
- The first line of input contains three space separated integers
, , . This means the number of the servers is , a list of changes of the state of the lines is given, and we need to know the number of different pieces of information contained in servers. - The
-th line of the following lines contains space separated integers , . This means the line , when it is built, connects the server and the server . - The
-th line of the following lines contains an integer . This means the state of the line is changed at time . Namely, if the line is unavailable just before time , this line is built at time . If the line is available just before time , this line becomes unavailable at time . When the state is changed at time , all the synchronization processes will be finished before time . - The
-th line of the following lines contains an integer . This means we need to know the number of different pieces of information contained in the server in the end.
Output Specification
Write
Constraints
All input data satisfy the following conditions.
. . . , , . . .- The values of
are distinct. - If all of the lines are built, there will be a route from one server to another server through the lines.
Subtasks
Subtask 1 [30 points]
is satisfied.
Subtask 2 [30 points]
, are satisfied.
Subtask 3 [40 points]
No additional constraints.
Sample Input
5 6 3
1 2
1 3
2 4
2 5
1
2
1
4
4
3
1
4
5
Sample Output
3
5
4
Explanation for Sample
In the beginning, we assume the server
- At time 1, the line 1 is built and the servers 1, 2 become connected. Then, both of the servers 1, 2 contain the pieces 1, 2 of information.
- At time 2, the line 2 is built, and the server 1, 3 become connected. Including the line 1, the servers 1, 2, 3 are connected. The servers 1, 2, 3 contain the pieces 1, 2, 3 of information.
- At time 3, the line 1 becomes unavailable because it was available just before this moment.
- At time 4, the line 4 is built and the servers 2, 5 become connected. Both of the servers 2, 5 contain the pieces 1, 2, 3, 5 of information. Note that the servers 1, 2 can not exchange pieces of information each other because the line 1 became unavailable.
- At time 5, the line 4 becomes unavailable.
- At time 6, the line 3 is built and the servers 2, 4 become connected. Then, both of the servers 2, 4 contain the pieces 1, 2, 3, 4, 5 of information.
As explained above, in the end, the servers 1, 4, 5 have 3, 5, 4 different pieces of information, respectively.
Comments