#P15949. [JOI Final 2026] JOI 国的节日 3 / Festivals in JOI Kingdom 3
[JOI Final 2026] JOI 国的节日 3 / Festivals in JOI Kingdom 3
Problem Description
JOI Kingdom consists of cities and highways. The cities are numbered through , and the highways are numbered through . It is possible to travel from any city to any other city by traversing a number of highways.
Each city has a popularity, represented by a non-negative integer. The popularity of city () is initially . Each highway has a travel time, represented by a positive integer. Highway () connects city and city , and its travel time is initially .
Each city in JOI Kingdom has a cauldron. JOI Kingdom keeps its tradition that, in a festival, cities ignite their cauldrons, and these ignitions signal the departure of parades from those cities.
City is adjacent to city if these two cities are directly connected by a highway. At the exact moment when a city ignites its cauldron, one parade will depart from this city for each of its adjacent cities, spending time equal to the travel time of the corresponding highway. To be precise, for two adjacent cities and , the parade from city reaches city at time , where is the time when the cauldron of city is ignited, and is the travel time of the highway connecting cities and .
Some cities ignite their cauldron the moment the festival starts, while other cities only do so after the festival heats up enough. Let the time be the start of the festival. For the city whose popularity is , the time when city ignites its cauldron is determined as follows:
- If , city ignites its cauldron at time .
- If , city ignites its cauldron at the time when the number of parades that have arrived from adjacent cities becomes at least . If this never happens, city never ignites its cauldron.
Mr. K will stay at JOI Kingdom. During his stay, JOI Kingdom will have events related to its festival. These events are numbered through from earliest to latest.
Event () is one of the following types:
- Type : The popularity of city changes to .
- Type : The travel time of highway changes to .
- Type : Mr. K visits city . Assuming a festival starts at this moment, you must determine whether city would ignite its cauldron, and if so, calculate the time that the cauldron is ignited.
Write a program which, given the structure of JOI Kingdom, popularity of each city, travel time of each highway, and details of the events, for each Type event, determines when the city Mr. K visits ignites its cauldron.
Input Format
Read the following data from the standard input.
(Query )
(Query )
(Query ) represents the details of event (). In (Query ), space-separated integers are written. Let be the first integer. is , , or , which means the type of event . Then (Query ) means as follows:
- If , there are two more integers written in this order. This means that the popularity of city changes to .
- If , there are two more integers written in this order. This means that the travel time of highway changes to .
- If , there is one more integer written. This means Mr. K visits city and, assuming a festival starts at this moment, you must determine the time that the cauldron at city is ignited.
Output Format
To standard output, output the following in one line for each event () with , in the increasing order of .
- If the city Mr. K visits would ignite its cauldron, output the time that the cauldron is ignited.
- Otherwise, output .
7
1 2 30
2 3 30
1 4 70
2 5 20
1 6 10
2 7 50
2
3
0
0
0
1
0
8
3 1
1 6 0
3 1
2 6 10
3 1
1 2 7
1 6 7
3 1
80
70
60
-1
6
1 2 10
1 3 30
1 4 50
1 5 30
1 6 10
2
0
0
0
0
1
10
3 1
2 3 20
3 1
1 6 0
3 1
1 1 4
3 1
1 2 6
1 3 6
3 1
30
20
10
30
-1
Hint
Sample 1
In the festival considered in event , the times when the cities ignite their cauldrons are as follows:
- At time , cities ignite their cauldrons.
- At time , city ignites its cauldron. By then, the parades from cities have reached city .
- At time , city ignites its cauldron. By then, the parades from cities have reached city .
- At time , city ignites its cauldron. By then, the parade from city has reached city . Since city would ignite its cauldron at time , output .
In the festival considered in event , the times when the cities ignite their cauldrons are as follows:
- At time , cities ignite their cauldrons.
- At time , city ignites its cauldron. By then, the parades from cities have reached city .
- At time , city ignites its cauldron. By then, the parades from cities have reached city . Since city would ignite its cauldron at time , output .
In the festival considered in event , the times when the cities ignite their cauldrons are as follows:
- At time , cities ignite their cauldrons.
- At time , city ignites its cauldron. By then, the parades from cities have reached city .
- At time , city ignites its cauldron. By then, the parades from cities have reached city . Since city would ignite its cauldron at time , output .
In the festival considered in event , the times when the cities ignite their cauldrons are as follows:
- At time , cities ignite their cauldrons. Cities would never ignite their cauldrons. Since city would never ignite its cauldron, output . This sample input satisfies the constraints of Subtasks .
Sample 2
This sample input satisfies the constraints of Subtasks .
Constraints
- .
- ().
- ().
- ().
- It is possible to travel from any city to any other city by traversing a number of highways.
- .
- If , we have , ().
- If , we have , ().
- If , we have ().
- Given values are all integers.
Subtasks
- (6 points) , .
- (7 points) , (). If , we have ().
- (14 points) is divisible by . , (). If , we have ().
- (25 points) . If , we have ().
- (12 points) If , we have ().
- (22 points) ().
- (14 points) No additional constraints.