## JOI '13 - Synchronization

View as PDF

Points: 40 (partial)
Time limit: 5.0s
Memory limit: 64M

Problem type
##### JOI Open Contest

The JOI Co., Ltd. has servers in total around the world. Each server contains an important piece of information. Different servers contain different pieces of information. The JOI Co., Ltd. is now building digital lines between the servers so that the pieces of information will be shared with the servers. When a line is built between two servers, pieces of information can be exchanged between them. It is possible to exchange pieces of information from one server to another server which is reachable through the lines which are already built.

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 lines can be built. After the lines are built, there will be a unique route to exchange pieces of information from one server to another server without passing through the same server more than once.

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 (), the state of exactly one line is changed.

We need to know the number of different pieces of information contained in some of the servers at time .

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 lines to the standard output. The -th line () should contain an integer, the number of different pieces of information contained in the server in the end.

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

• is satisfied.
• , () are satisfied.

#### 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 Output

In the beginning, we assume the server () contains the piece of information.

• 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