#P15665. [ICPC 2025 Jakarta R] Travelling Taro Trains
[ICPC 2025 Jakarta R] Travelling Taro Trains
题目描述
Taro is travelling within a country, which consists of cities numbered from to . There are also train companies, numbered from to , that operate the trains within the nation. Initially, there are one-way train services, each of which can be described as a triple , meaning that there are trains operated by company that goes from city to city .
Taro is currently in city . In the next months, one of the following three events may happen.
- : company a new train service that goes from city to city . In other words, add to the train network.
- : company its train service that goes from city to city . In other words, remove from the train network.
- : Taro either in the city he is currently in, or one of the trains operated by company from the city he is currently in to another city.
It is guaranteed to you that the existing services are always distinct throughout the course of events, and event always removes a currently existing service.
Every time an event happens, find the number of different cities Taro can possibly be in, given the course of events so far.
输入格式
The first line contains three integers , , , and (; ).
Each of the next lines contains three integers , , (; ; ) describing the initial train services.
Each of the next lines contains an event as described above.
The input guarantees that the existing services are always distinct throughout the event.
输出格式
For each event , output, in a single line, the number of different cities Taro can possibly be in.
6 4 2 5
1 3 1
3 6 2
3 2 2
3 5 2
3 2
3 1
1 1 4 2
2 3 6 2
3 2
1
2
5
提示
Initially, Taro is in city .
- In the first event , there are no train services operated by company that departs from city , so Taro has to stay in city .
- In the second event , Taro can either stay in city , or take the service and end in city . Because Taro can be in either city or , you have to output .
- In the third event , the existing train services are , , , . If Taro is currently in city , he can take service and end in city . If Taro is currently in city , he can take services or and end in city or respectively. Since he can possibly in city , , , , and , you have to output .