#P9598. [JOI Open 2018] 山体滑坡 / Collapse
[JOI Open 2018] 山体滑坡 / Collapse
Problem Description
Mr. I has a -day cable construction plan. The plan for day is given by three integers , which mean:
- If , they will install a cable connecting town and town . It is guaranteed that at the beginning of day , there is no cable between towns and .
- If , they will remove a cable connecting town and town . It is guaranteed that at the beginning of day , there is a cable between towns and .
Landslides often happen in the country of JOI. If a landslide happens between towns and , then only cables whose two endpoints are both numbered at most , or both numbered at least , are usable. In JOI, whenever a landslide happens, they choose some towns to build base stations. The base stations must satisfy that for every town, it can be connected to a base station through some usable cables.
During the construction phase, Mr. I is already thinking about how many base stations should be built when a landslide happens. He has questions. The -th question is given by two integers , meaning that he wants to know: after day ends, if a landslide happens between towns and , what is the minimum number of base stations that should be built.
As Mr. I’s assistant, you are asked to write a program to answer Mr. I’s questions.
Input Format
On LOJ this is an interactive problem. For convenience, here it is judged in the traditional (non-interactive) way.
The first line contains three integers .
The next lines each contain three integers .
The next lines each contain two integers .
Output Format
Output lines. The -th line should output , the answer to the -th question.
5 8 2
0 0 1
0 1 3
0 2 4
0 4 0
1 1 3
0 0 3
0 1 2
0 4 3
3 1
7 3
3
2
Hint
Sample
Consider the case with towns. In what follows, represents a cable connecting town and town .
- Suppose that when there are four cables , a landslide happens between towns and . Cables and become unusable, so the usable cables are and . You need to build base stations in towns . The minimum number of base stations is .
- Suppose that when there are six cables and , a landslide happens between towns and . Cables and become unusable, so the usable cables are and . You need to build base stations in towns and . The minimum number of base stations is .
Constraints
This problem has four subtasks. The scores and additional constraints are shown in the table below:
| Subtask ID | Score | Additional Constraints | ||
|---|---|---|---|---|
| None | ||||
| All are equal | ||||
| None |
Translated by ChatGPT 5