#P10658. BZOJ2959 长跑
BZOJ2959 长跑
Background
A school has launched a popular “Sunshine Long-Distance Run” activity. To “work healthily for the motherland for fifty years”, students leave their dorms, classrooms, and labs to join a -meter run on the playground. In no time, the playground becomes packed with people, creating an unprecedented lively scene.
Problem Description
To help students supervise themselves better, the school uses a card-swiping system. There are locations in the school, labeled by integers . Each location has several card-swiping machines.
There are three types of events:
- Build a track connecting location and location .
- The number of card-swiping machines at location becomes .
- Perform a long-distance run. Ask: if a student starts from location and finally arrives at location , what is the maximum number of times they can swipe their card. The specific rules are:
- When the student arrives at a location, they may swipe on every machine there. But each machine can be used at most once. That is, even if they visit the same location multiple times, they cannot swipe on the same machine more than once. For safety, each track must be assigned a direction, and it can only be traveled one-way along that direction. The maximum number of swipes is defined as: after choosing directions for all tracks arbitrarily, and choosing any path from to , the maximum total number of swipes possible.
Input Format
The first line contains two positive integers .
The second line contains positive integers. The -th integer is the number of card-swiping machines at location .
The next lines each contain three non-negative integers , describing one event. is the event type, and are the two parameters of the event.
Output Format
For each event with , output one line containing one integer: the maximum number of swipes possible when traveling from to along some path, with track directions chosen arbitrarily. If cannot be reached, output .
9 31
10 20 30 40 50 60 70 80 90
3 1 2
1 1 3
1 1 2
1 8 9
1 2 4
1 2 5
1 4 6
1 4 7
3 1 8
3 8 8
1 8 9
3 8 8
3 7 5
3 7 3
1 4 1
3 7 5
3 7 3
1 5 7
3 6 5
3 3 6
1 2 4
1 5 5
3 3 6
2 8 180
3 8 8
2 9 190
3 9 9
2 5 150
3 3 6
2 1 210
3 3 6
-1
-1
80
170
180
170
190
170
250
280
280
270
370
380
580
Hint
For all testdata, , .
It is guaranteed that initially there are no tracks between any locations.
In each line, adjacent numbers are separated by a single space.
All location indices are between and . The number of card-swiping machines at each location never exceeds . .
Translated by ChatGPT 5